Posted By

nate63179 on 12/08/09


Tagged

javascript html


Versions (?)

Grab GET params with Javascript


 / Published in: JavaScript
 

url: http://www.example.com/?foo=bar

usage: $_GET['foo'] // 'bar'

  1. var $_GET = {};
  2. document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
  3. function decode(s) {
  4. return decodeURIComponent(s.split("+").join(" "));
  5. }
  6.  
  7. $_GET[decode(arguments[1])] = decode(arguments[2]);
  8. });

Report this snippet  

You need to login to post a comment.