Javascript jQuery URL parameters
Hello folks, sometimes we need to get the URL parameters from the GET method, so I decided to create a small plugin for jQuery and get it.
/** * $.URL() - URL parameters via GET method * * It is a simple jQuery plugin to get * the parameters setted via GET method * * $.URL() to initialize it * $.URL.param('name') to get a specific value of the parameters * * @author Miguel Gocobachi <[email protected]> */ if (window.jQuery) { $(function($) { $.URL = function() { var params = window.location.href.slice( window.location.href.indexOf('?') + 1 ).split('&'); if (params.length > 0) { $.URL.parameters = {}; $.each(params, function(key, param) { param = param.split('='); $.URL.parameters[param[0]] = param[1]; }); } }; $.URL.param = function(name) { if (('undefined' === typeof name) || 'undefined' === typeof $.URL.parameters[name]) { return null; } return $.URL.parameters[name]; }; $.URL.parameters = null; }(jQuery)); }
Also the code can be downloaded from https://github.com/mgocobachi/urlgetty















