I need a way to create an object
from a location value. For example if I have the value:
'http://www.legis.state.pa.us/cfdocs/billinfo/bill_history.cfm?syear=2007&sind=0&body=*S*&type=B&bn=1'
which I get from doc.location.href();
I would like to make the following object:
myObject = {
syear : '2007',
snid : '0',
body : 's',
type : 'B',
bn : '1',
};
Thanks!
D
Progress
For some reason I couldn't get the extended function/object to work in my system. I think because my code is running inside a firefox extension and outside of the document context. Or maybe it had something to do with the jQuery.noConflict();
(I don't know).
But, I ended up needing to take out the function from the object and editing it a little in order to get it to work for me:
function getURLParam(URL, strParamName){
var qString;
var returnVal = new Array();
if (URL==null) return null;
if ( URL.indexOf("?") > -1 ){
var strQueryString = URL.substr(URL.indexOf("?")+1);
qString = strQueryString.split("&");
}
else {
return null;
}
for (var i=0;i<qString.length; i++){
if (escape(unescape(qString[i].split("=")[0])) == strParamName){
returnVal.push(qString[i].split("=")[1]);
}
}
if (returnVal.length==0) return null;
else if (returnVal.length==1) return returnVal[0];
else return returnVal;
}