read the GET variables in url JQuery

var split = location.search.replace('?', '').split('=')

split[0] is your var name, and split[1] is your var value. You actually don't really need jQuery for that piece of code ;)

As for twiz's comment, splitting multiple variables can be done like that:

var split = location.search.replace('?', '').split('&').map(function(val){
  return val.split('=');
});

You can access variable name by split[index][0] and value by split[index][1].

Of course you can use the second snippet instead of the first one for one variable too.


I use this in my default javascript file.

var get = [];
location.search.replace('?', '').split('&').forEach(function (val) {
    split = val.split("=", 2);
    get[split[0]] = split[1];
});

Now you can use them by name:

get["var1"]