Jigs Jigs - 2 years ago 99
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download