Jigs Jigs - 5 months ago 9x
Javascript Question

extract GET parameters from a user inputed url with javascript

I am looking to use javascript to extract the GET parameters from a user inputed url.

For example is a user enters a url say:


I could get the v parameter

'ee925OTFBCA' as a variable

Thanks in Advance.


This should do the trick

// include this somewhere available 
var Query = (function(){
    var query = {}, pair, search = location.search.substring(1).split("&"), i = search.length;
    while (i--) {
        pair = search[i].split("=");
        query[pair[0]] = decodeURIComponent(pair[1]);
    return query;

var v= Query["v"]

This only runs its computation once and creates an object with name/value pairs corresponding to those supplied as parameters