/ Published in: JavaScript
Interface
- function()
- function (string globalvariablename)
- function (string globalvariablename, string attributevaluepair)
Construct an array of attribute-value pairs from the search part of the url or an user specified string.
The result is returned from an anonymous function so the global name space won't be corrupted. A user can also provide a string to be the name of a global variable to store the result table.
BookmarkletThe bookmarklet is generated by Closure Compiler .
Expand |
Embed | Plain Text
/* <bookmarklet> *\ javascript:(function(d,a){var b,c={};if(!a)a=location.search;a=a.replace(/^\?/,"");a=a.split("&");for(b=0;b<a.length;b++)if(a[b]){a[b]=a[b].split("=");c[a[b][0]]=a[b][1]||""}if(typeof d=="string")this[d]=c;return c})(); \* </bookmarklet> */ (function(identifier, search) { var cx; var $_GET = {}; /* Set the default value of search. */ if (!search) search = location.search; /* Remove the leading question mark. */ search = search.replace(/^\?/, ""); /* Split attribute-value pairs. */ search = search.split("&"); for (cx = 0; cx < search.length; cx++) { /* Skip empty strings. */ if (!search[cx]) continue; /* Split attributes and values. */ search[cx] = search[cx].split("="); /** * Map these attributes and values. * Undefined, the value is made an empty string. */ $_GET[search[cx][0]] = search[cx][1] || ""; } /* Define a global variable and store the table. */ if (typeof identifier == "string") this[identifier] = $_GET; return $_GET; })();
You need to login to post a comment.
