Posted By

nelsnelson on 03/18/09


Tagged

url javascript parameters


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

LeeRJohnson
umang_nine
Priestd09


Javascript function to get URL query string parameters


 / Published in: JavaScript
 

URL: http://www.netlobo.com/url_query_string_javascript.html

Here is a small function [lobo235] wrote that will parse the window.location.href value and return the value for the parameter you specify. It does this using javascript's built in regular expressions.

  1. function gup( 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 results[1];
  11. }

Report this snippet  

You need to login to post a comment.