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.