Retrieve URL params with jQuery


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.