0

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;
}

2 Answers 2

1

this might be useful:

http://www.mathias-bank.de/2006/10/28/jquery-plugin-geturlparam/

using the above you can easily construct the hash

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was looking for. And the source code is very small. Thanks!
0

jQuery Url Parser should do exactly what you want.

jQuery.url.setUrl('http://www.legis.state.pa.us/cfdocs/billinfo/bill_history.cfm?syear=2007&sind=0&body=S&type=B&bn=1').param('syear');

returns 2007

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.