Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.location.search will return everything from the ? on. This will remove the ?, use split to separate into key/value arrays, then assign named properties to the params object:
- function getSearchParameters() {
- var prmstr = window.location.search.substr(1);
- return prmstr != null && prmstr != "" ? transformToAssocArray(prmstr) : {};
- }
- function transformToAssocArray( prmstr ) {
- var params = {};
- var prmarr = prmstr.split("&");
- for ( var i = 0; i < prmarr.length; i++) {
- var tmparr = prmarr[i].split("=");
- params[tmparr[0]] = tmparr[1];
- }
- return params;
- }
- var params = getSearchParameters();
- You can then get the test parameter from http://myurl.com/?test=1 by calling params.test.
Advertisement
Add Comment
Please, Sign In to add comment