Description
Creates a get() function that can be used to parse the query string.
Demonstration
Reload the page with a query string.
get('company') Gets the value keyed as "company"
get('language') Gets the value keyed as "language"
get() Gets all values
Code
<script language="javascript" type="text/javascript"> function get(val) { if (val != "undefined" && val != undefined) { querystring = window.location.search.substr(1).split(/&/); for (i=0; i<querystring.length; i++) { pairs = querystring[i].split(/=/); key = pairs[0]; if (key == val) { query = pairs[1]; break; } else { query = "undefined key"; } } } else { query = window.location.search.substr(1); } alert (query); } </script>
Tested in: IE6, Opera 7, NN4.7, NN7, and Mozilla 1.2.
Works in: IE6, Opera 7, NN4.7, NN7 and Mozilla 1.2.
Doesn't work in: N/A
Copyright© 2003, Infinity Web Design