Posted By

nerdfiles on 03/07/09


Tagged

get url javascript variables parameters


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Anber
Alphawolf
wizard04


Get URL Params with JavaScript


 / Published in: JavaScript
 

Not my code. See: http://www.netlobo.com/urlquerystring_javascript.html

  1. function gup( name ) {
  2. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  3. var regexS = "[\\?&]"+name+"=([^&#]*)";
  4. var regex = new RegExp( regexS );
  5. var results = regex.exec( window.location.href );
  6. if( results == null )
  7. return "";
  8. else
  9. return results[1];
  10. }
  11.  
  12. // Example: gup('cat') will give you "meow" if the URL is http://example.com/?cat=meow

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Alphawolf on August 31, 2009

Very nice one.

You need to login to post a comment.