Posted By

built2fall on 01/30/10


Tagged

url javascript querystring


Versions (?)

Get querystring value by name


 / Published in: JavaScript
 

  1. function getParameterByName( name )
  2. {
  3. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  4. var regexS = "[\\?&]"+name+"=([^&#]*)";
  5. var regex = new RegExp( regexS );
  6. var results = regex.exec( window.location.href );
  7. if( results == null )
  8. return "";
  9. else
  10. return decodeURIComponent(results[1].replace(/\+/g, " "));
  11. }
  12.  
  13. // --
  14.  
  15. var urlParams = {};
  16. (function () {
  17. var e,
  18. a = /\+/g, // Regex for replacing addition symbol with a space
  19. r = /([^&=]+)=?([^&]*)/g,
  20. d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
  21. q = window.location.search.substring(1);
  22.  
  23. while (e = r.exec(q))
  24. urlParams[d(e[1])] = d(e[2]);
  25. })();

Report this snippet  

You need to login to post a comment.