Skip to content

Instantly share code, notes, and snippets.

@element6
Created October 14, 2015 06:12
Show Gist options
  • Save element6/a98122b888a5707c5cb3 to your computer and use it in GitHub Desktop.
Save element6/a98122b888a5707c5cb3 to your computer and use it in GitHub Desktop.
put query string into jquery object
$.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;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
@element6
Copy link
Author

Get query parameter

        function getParameterByName(name, url) {
            url = url || window.location.href;
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                    results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment