Oct 12, 2010

Getting the URL parameter in Javascript

Sample URL : http://mysite/sites/Demos/Training/PCM.aspx?ID=429

var paramID=GetValue('ID');

alert('Result ID '+paramID)

function GetValue(name)
{
   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
   var regexS = "[\\?&]"+name+"=([^&#]*)";
   var regex = new RegExp( regexS );
   var results = regex.exec( unescape(window.location.href) );
   if( results == null )
     return "";
  else
    return results[1];
}

1 comment:

  1. thanks a lot for your valuable info, how long hw you been working for sharepoint, can i get an email from i wanna discuss more, here is my email address: chittelacheers@gmail.com or rshankar.7956@gmail.com

    ReplyDelete