get params in JS


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

get paramt


Copy this code and paste it in your HTML
  1. // make GET-Params accessible in JS
  2. (function(){
  3. window.getparams = {};
  4. var s = window.location.search.substring(1).split('&');
  5. if(!s.length) return;
  6. for(var i = 0; i < s.length; i++) {
  7. var parts = s[i].split('=');
  8. window.getparams[unescape(parts[0])] = unescape(parts[1]);
  9. }
  10. }())
  11.  
  12. //use: window.getparams['id']

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.