Posted By

iTony on 02/11/08


Tagged

regex url javascript


Versions (?)

retrieve values from a url


 / Published in: JavaScript
 

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

This makes it easy to retrieve certain value from a url with different values appended to it.

  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.