Possible Duplicate:
Get query string values in JavaScript
I need a function to read query string value?
If I give key then the method should return the corresponding value.
Please help..
Possible Duplicate:
Get query string values in JavaScript
I need a function to read query string value?
If I give key then the method should return the corresponding value.
Please help..
Try this will help
function fnGetValueByKey(key)
{
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + key + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
Ive allways used the following and it seems to work
function urlParam(name){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec (window.location.href);
if (results == null)
return "";
else
return results[1];
}
You just need to call urlParam("yourName");
and it will return your value;
yAccess desired query using getQuery('mykey');
function getQuery( key) {
var hu = window.location.search.substring(1), gy = hu.split("&"), val;
keyValue = {};
for ( var i = 0; i < gy.length; i++) {
val = gy[i].split("=");
keyValue[val[0]] = val[1];
}
return keyValue[key];
}