Created
May 29, 2015 13:06
-
-
Save jmahc/d21e90f027c86f5c7943 to your computer and use it in GitHub Desktop.
This javascript function grabs any query parameters and stores them in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getQueryParams = function () { | |
var params = []; | |
var query = window.location.search; | |
query = query.slice(1, query.length); | |
var nv = query.split('&'); | |
for (var i = 0; i < nv.length; i++) { | |
var q = nv[i].split('='); | |
params[q[0]] = q[1]; | |
} | |
return params; | |
}; | |
//-- Example -- | |
//www.example.com?product=1234&type=Shirt | |
var parameters = getQueryParams(); //Calls the function and stores values into variable 'parameters' | |
var productNumber = parameters.product; // 1234 | |
var productType = parameters.type; // Shirt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment