Posted By

charmcitycoder on 11/14/08


Tagged

javascript querystring variable


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

VaiT
natalan
ginoplusio
charmcitycoder


Function - Get querystring variable


 / Published in: JavaScript
 

URL: http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx

Many thanks to bloggingdeveloper.com for this one. Works like a charm. Usage is similar to server side built-in functions.

  1. function getQuerystring(key, default_)
  2. {
  3. if (default_==null) default_="";
  4. key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  5. var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  6. var qs = regex.exec(window.location.href);
  7. if(qs == null)
  8. return default_;
  9. else
  10. return qs[1];
  11. }

Report this snippet  

You need to login to post a comment.