Summary:
Sometimes in jQuery you need to grab a paramater from a URL.
e.g. http://dummy.com/?technology=jquery&blog=jquerybyexample
Solution:
Add the following code to your javascript file:
var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } };
Now you can target a paramater as follows:
var tech = getUrlParameter('technology'); var blog = getUrlParameter('blog');