Parse a HTTP GET query string with Javascript


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



Copy this code and paste it in your HTML
  1. /* Parse GET parameters (based on http://www.netlobo.com/url_query_string_javascript.html) */
  2. function parseHttpGet(key){
  3. key = key.replace(/[[]/,"\[").replace(/[]]/,"\]");
  4. var regexS = "[\?&]"+key+"=([^&#]*)";
  5. var regex = new RegExp( regexS );
  6. var results = regex.exec(window.location.href);
  7. return ( results != null ? results[1] : false );
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.