Click to See Complete Forum and Search --> : URL info into javascript


OhLordy
05-28-2003, 03:55 AM
Hi,
How can I pull information from the URL into javascript?
Thank you in advance
Rob

OhLordy
05-28-2003, 04:01 AM
OK, sorry, crap question. Found out now that I need to use document.URL however I have another problem.
I only want the GET data from the URL. In PHP I would use the explode function with ? or & as the parameter to explode on. Is there a similar function that I should use in Javascript or is there some other way around the problem?
Thank You
Rob

Charles
05-28-2003, 05:36 AM
Use the Window.location.search property instead and then use Regular Expressions to split up the key/value pairs. Here's a little Query class. Query objects will have as properties all of the key/value pairs. You're welcome.

function Query () {
if (self.location.search) {
this.query = self.location.search.replace(/^\?/, '');
var pairs = this.query.split('&');
for (i=0;i<pairs.length;i++) {if (/(.*)=(.*)/.test(pairs[i])) this[unescape(RegExp.$1)] = unescape(RegExp.$2)};
}
}

Query.prototype.toString = function () {return this.query}

var query = new Query();

OhLordy
05-28-2003, 08:30 AM
Thank you! :)