Skip to content

Instantly share code, notes, and snippets.

@crates
Created January 13, 2020 15:47
Show Gist options
  • Save crates/b01df1847c45ac264cb99f774fd88f90 to your computer and use it in GitHub Desktop.
Save crates/b01df1847c45ac264cb99f774fd88f90 to your computer and use it in GitHub Desktop.
jQuery prototype to parse URL query strings
(function($) { // Prototypes a function to parse URL query strings:
$.QueryString = (function(a) {
if (a === "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length !== 2) continue;
try {
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
} catch (excep) { }
} // for
return b;
})(window.location.search.substr(1).split('&'));
})(jQuery); // End of URL query string parsing function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment