Skip to content

Instantly share code, notes, and snippets.

@sanampatel
Created September 4, 2017 17:23
Show Gist options
  • Select an option

  • Save sanampatel/5f54c23cf59bde4e6196cf7ec9c554c4 to your computer and use it in GitHub Desktop.

Select an option

Save sanampatel/5f54c23cf59bde4e6196cf7ec9c554c4 to your computer and use it in GitHub Desktop.
URL Parameter with jQuery
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];
}
}
};
/*
Use!
var tech = getUrlParameter('technology');
var blog = getUrlParameter('blog');
For more :
https://stackoverflow.com/questions/19491336/get-url-parameter-jquery-or-how-to-get-query-string-values-in-js
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment