Return to Snippet

Revision: 50706
at August 31, 2011 01:27 by ddavidd


Updated Code
var uri = window.location.href; //http://www.yoururl.com?id=test
var queryString = {};
uri.replace(
    new RegExp("([^?=&]+)(=([^&]*))?", "g"),
    function($0, $1, $2, $3) { queryString[$1] = $3; }
);
console.log(queryString['id']); //returns 'test' or 'undefined' if not found

Revision: 50705
at August 31, 2011 01:26 by ddavidd


Updated Code
var uri = window.location.href; //http://www.yoururl.com?id=test
var queryString = {};
uri.replace(
    new RegExp("([^?=&]+)(=([^&]*))?", "g"),
    function($0, $1, $2, $3) { queryString[$1] = $3; }
);
console.log('ID: ' + queryString['id']); //returns 'test' or 'undefined' if not found

Revision: 50704
at August 31, 2011 01:24 by ddavidd


Initial Code
var uri = window.location.href;
var queryString = {};
uri.replace(
    new RegExp("([^?=&]+)(=([^&]*))?", "g"),
    function($0, $1, $2, $3) { queryString[$1] = $3; }
);
console.log('ID: ' + queryString['id']);

Initial URL
http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/

Initial Description

                                

Initial Title
Parse a query string into an object

Initial Tags
query

Initial Language
JavaScript