Retrieve Query String Variables Javascript


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



Copy this code and paste it in your HTML
  1. function getQuerystring(key, default_)
  2. {
  3. if (default_==null) default_="";
  4. key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  5. var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  6. var qs = regex.exec(window.location.href);
  7. if(qs == null)
  8. return default_;
  9. else
  10. return qs[1];
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.