RSS | Archive | Random | E-mail

About

Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.

Links

Codepuzzling main site
Development site
ByteStrike italian blog
Follow me on Twitter

My Life Style

while(passion) {
  try {
    myLife.run();
  }catch(LifeExceptions) {  
    stronger++;
    continue;
   }
}

Following

5 October 09

[JS] How to get a querystring value given the key

Suppose you have an URL like this: www.host.com?m=5&lang=it. If you want to retrive the value of lang, you could simply use this function:

function parseURL(url,key)
{
  var reQS = new RegExp("[?&]"+key+"=([^&$]*)", "i");
  var offset = url.search(reQS);
  return ( offset >= 0 ) ? RegExp.$1 : null;
}

// usage
var myKey = parseURL("www.host.com?m=5&lang=it","lang")
Via blog.falafel.com

Comments (View)
blog comments powered by Disqus
Themed by Hunson. Originally by Josh