I wrote this a few days ago:
It parses query strings, example at bottom
parseQuery = function() {
window.query = {};
var qstr = location.search.substr(1).split('&');
var qstr_len = qstr.length;
for(var i=0; i < qstr_len; i++) {
var q = (qstr[i] ? qstr[i].split('=') : []);
if(q.length) {
firstBracket = q[0].indexOf('[');
if(firstBracket != -1 && -1 != (secondBracket = q[0].indexOf(']',
firstBracket))) {
var queryString = q[0].substr(0, firstBracket);
window.query[queryString] = window.query[queryString] || [];
if(firstBracket+1 == secondBracket) {
window.query[queryString].push(q[1]);
} else {
queryIndex = q[0].substr(firstBracket+1, (secondBracket-
(firstBracket+1)));
window.query[queryString][queryIndex] = q[1];
}
} else {
window.query[q[0]] = q[1];
}
}
}
window['$_GET'] = window.query;
}
/**
Example:
URL:
http://example.com/?aff=raja&c[]=1&x[cool]=2
>>parseQuery()
>>window.query['c'][0]
"1"
>>window.query['aff']
"raja"
>>window.query['x']['cool']
"2"
**/
On Aug 20, 9:12 am, timchi...@gmail.com wrote:
I have the following request URL in an ASPx page:
http://crm/custom/fileviewer/default.aspx?NAME
I want to be able to parse the requesting URL and pass NAME into a
variable.
Can anyone give me the code to do this?
Cheers
Tim