Example
The code is as follows |
Copy Code |
<script> var $_get = new Object (); var _rep = document.location.search.replace (/(\?| &) ([\w\d_]+) = ([^&]+)/g, "_get[' $ ']= ' $"); Eval (' $ ' +unescape (_REP.SUBSTR (0,_rep.length-1))); For (i in $_get) document.write (i+ ' => ' +$_get[i]+ ' <br> '); </script>
|
Add an IE Firefox compatible
Character Read
The code is as follows |
Copy Code |
<script language= "JavaScript" > <!-- function Request (strName) { var strhref = Window.document.location.href; var intpos = Strhref.indexof ("?"); var strright = strhref.substr (intpos + 1); var arrtmp = Strright.split ("&"); for (var i = 0; i < arrtmp.length; i++) { var arrtemp = arrtmp[i].split ("="); if (arrtemp[0].touppercase () = = Strname.touppercase ()) return arrtemp[1]; } Return ""; } Alert (Request ("id")) --> </SCRIPT> |
Example Two
The code is as follows |
Copy Code |
* * $_get[the Address bar get parameter like PHP's ' arg '] function Getargs () { var args = {}; var query = location.search.substring (1); Get query string var pairs = Query.split ("&"); Break at Ampersand for (var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexof (' = '); Look for "Name=value" if (pos = = 1) continue; If not found, skip var argname = pairs[i].substring (0,pos); Extract the name var value = pairs[i].substring (pos+1); Extract the value Value = decodeuricomponent (value); Decode it, if needed Args[argname] = value; Store as a property } return args; Return the object } /* Use method * * * * Url:http://www.111cn.net user=funsion&age=26 * * Alert (Getargs () [' User ']); Output funsion Alert (Getargs () [' Age ']); Output 26 |