Posted By

garside on 01/27/09


Tagged

url jquery variable param


Versions (?)

Who likes this?

25 people have marked this snippet as a favorite

sulfurito
troynt
stavelin
bryandease
umang_nine
delikassap
danielfilho
Vordreller
sheedy
gtalmes
vali29
cesgra
anobre
kikuchiyosesa
brandonjp
zeropx
vkolev
bobbym245
laurentzziu
rijnbeek
wirenaught
chrisaiv
victorcastelan
jillella
ringo380


Retrieve URL params with jQuery


 / Published in: jQuery
 

  1. $.urlParam = function(name){
  2. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  3. return results[1] || 0;
  4. }
  5.  
  6. // example.com?someparam=name&otherparam=8&id=6
  7. $.urlParam('someparam'); // name
  8. $.urlParam('id'); // 6
  9. $.urlParam('notavar'); // null

Report this snippet  

You need to login to post a comment.