Hey there!
Today I'm going to show you how to use URL parameters and values with jQuery.
Usually, URL parameters are used server side, but sometimes it's useful to just check the parameters in the URL client side in order to perform certain effects. Well, with this little snippet of code, it is possible to get the URL parameters using jQuery:
jQuery.getParams = function () {
var params = {};
var split = window.location.href.slice(
window.location.href.indexOf('?') + 1
).split('&');
for (var i = 0; i < split.length; i++) {
params[split[i].split('=')[0]] = split[i].split('=')[1]|| null;
}
return params;
}
You can either call this function by typing:
jQuery.getParams
or
$.getParams
For more, check out: http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
1 comments:
Of course, this code snippet doesn't really even rely on jQuery, it can just as easily be used without it.
Post a Comment