mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-09-01 16:53:54 +02:00
32 lines
805 B
JavaScript
32 lines
805 B
JavaScript
|
function parseQueryStringToDictionary(queryString=window.location.search) {
|
||
|
var dictionary = {};
|
||
|
|
||
|
// remove the '?' from the beginning of the
|
||
|
// if it exists
|
||
|
if (queryString.indexOf('?') === 0) {
|
||
|
queryString = queryString.substr(1);
|
||
|
}
|
||
|
|
||
|
// Step 1: separate out each key/value pair
|
||
|
var parts = queryString.split('&');
|
||
|
|
||
|
for (var i = 0; i < parts.length; i++) {
|
||
|
var p = parts[i];
|
||
|
// Step 2: Split Key/Value pair
|
||
|
var keyValuePair = p.split('=');
|
||
|
|
||
|
// Step 3: Add Key/Value pair to Dictionary object
|
||
|
var key = keyValuePair[0];
|
||
|
var value = keyValuePair[1];
|
||
|
|
||
|
// decode URI encoded string
|
||
|
value = decodeURIComponent(value);
|
||
|
value = value.replace(/\+/g, ' ');
|
||
|
|
||
|
dictionary[key] = value;
|
||
|
}
|
||
|
|
||
|
// Step 4: Return Dictionary Object
|
||
|
return dictionary;
|
||
|
}
|