2

How do I read the value of ID with a url similar to the following?

http://intranet/page.aspx?id=10
oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • possible duplicate of [Get QueryString values with jQuery](http://stackoverflow.com/questions/901115/get-querystring-values-with-jquery) – Roatin Marth Feb 07 '11 at 14:48

3 Answers3

2

You can use JQuery's URL parser plugin.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
2
function gup( name ) //stands for get url param
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

var my_param = gup( 'id' );

Here is the jsfiddle that uses a variable with a static url to test the output. This is done without using jQuery, however.

KJYe.Name
  • 16,969
  • 5
  • 48
  • 63
0

http://7php.com/javascript-using-jquery-to-find-url-querystring-or-url-params-a-simple-yet-effective-approach/

That link helped me to do the same, has jQuery and JavaScript examples.

Barrie Reader
  • 10,647
  • 11
  • 71
  • 139
  • Hello! I didn't downvote either, but I'm willing to guess the downvote is because you posted a link only answer, and if this link were to ever break, your answer would be useless. To get more upvotes *and* make sure your post is useful to future visitors, consider making an [edit] to your post to add in the example from the link. Links are helpful, but the best answers are self-contained and future proof! Good luck! :) – jamesmortensen Nov 23 '12 at 22:18