Query String in Javascript
Posted
by Ajith
on Stack Overflow
See other posts from Stack Overflow
or by Ajith
Published on 2010-04-13T05:25:10Z
Indexed on
2010/04/13
5:33 UTC
Read the original article
Hit count: 363
querystring
|JavaScript
How can we collect a query string value in javascript.
my script is like follows
http://192.168.10.5/study/gs.js?id=200
here i want to collect the id value in my gs.js script file.
For this i am using
function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}
var string_value = getQuerystring('id');
alert(string_value);
But it is not getting..Please anybody can correct me.Please
© Stack Overflow or respective owner