Quantcast
Viewing all articles
Browse latest Browse all 41

Reading querystring using javascript

Hi while searching for the same,

got the following javascript

q = location.search;

getParam = function(arg) {
if (q.indexOf(arg) >= 0) {
var pntr = q.indexOf(arg) + arg.length + 1;
if (q.indexOf(‘&’, pntr) >= 0) {
return q.substring(pntr, q.indexOf(‘&’, pntr));
} else {
return q.substring(pntr, q.length);
}
} else {
return null;
}
}

var objectId = getParam(‘oId’);

alert(objectId);

or better

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split(“&”);
for (i=0;i<gy.length;i++) {
ft = gy[i].split(“=”);
if (ft[0] == ji) {
return ft[1];
}
}
}

var pId= querySt(“pId”);
alert(pId);

http://ilovethecode.com/Javascript/Javascript-Tutorials-How_To-Easy/Get_Query_String_Using_Javascript.shtml

Here oId is the query string parameter whose value we need.

This works even if there are multiple query string parameters !

Bye…


Viewing all articles
Browse latest Browse all 41

Trending Articles