At the time, it was a bit out of my grasp to understand the subtlety of his code, I've since become a bit more knowledgeable concerning associative arrays and I've been able to whittle down my previous code example into something much more elegant.
I present to you for your scripting pleasure, the Better JavaScript Query String Parser:
var a = location.search.slice(1).split("&"), GET = [];
for (i in a) { GET[a[i].split("=")[0]] = a[i].split("=")[1]; }This will return an array named "GET" that consists of query string variables that can be referenced by the following example:
http://example.com/index.html?id=1001&fname=Ben&lname=Bradley
alert("id = " + GET["id"]);
alert("first name = " + GET["fname"]);
alert("last name = " + GET["lname"]);


0 comments:
Post a Comment