PDA

View Full Version : a beter way for url vars?



cipa
23 Feb 2011, 4:40 PM
Hi,

I am looking for a better way to get url parameters. Here's what I have so far


,viewQuestions: function(btn,e) {

var url = window.location.href;
var args = url.split('?');
var urlVars = Ext.urlDecode(args[1]);
location.href = '?a='+urlVars.a+'&id='+this.menu.record.id;

}

Maybe there is a faster and easier way to do this.

Thank you

Condor
24 Feb 2011, 2:32 AM
I would use:

var args = location.search.substr(1),
params = Ext.urlDecode(args),
newParams = {
a: params.a,
id: this.menu.record.id
};
location.search = '?' + Ext.urlEncode(newParams);

cipa
24 Feb 2011, 2:08 PM
Thank you

I ended up with this (a ; was needed before second location.search)


var args = location.search.substr(1),
params = Ext.urlDecode(args),
newParams = {a: params.a, id: this.menu.record.id};
location.search = '?' + Ext.urlEncode(newParams);