/ Published in: JavaScript
Extracts a string paremeter from the url query string. Basic operation wont handle multiples such as radio buttons etc. Just gets the first instance of the name and returns it's value.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function($) { /* --------------------------------------------------------------------- */ /* * Extracts a string parameter from the url query string. Basic operation * wont handle multiples such as radio buttons etc. Just gets the first * instance of the name and returns it's value. * * @param {String} Name of value to extract from URL QueryString. * @returns {String} Value of QueryString attribute or null if not found */ $.param = function(name) { var exp = new RegExp('[\\?&]' + name + '=([^&#]*)'); var param = exp.exec(window.location.href); return (param) ? param[1] : null; } })(jQuery); /* EXAMPLE USAGE */ /* Looks for a PageConfig object first then the Section querystring param */ $(function() { $('#tabs li a>span:contains(' + (($.PageConfig || {}).section || $.param("Section")) || "Home" + ')').parent().addClass("current"); });