Skip to content

Instantly share code, notes, and snippets.

@fhdalikhan
Created October 11, 2020 22:05
Show Gist options
  • Save fhdalikhan/356b04121b85a524f9f57498e9739e98 to your computer and use it in GitHub Desktop.
Save fhdalikhan/356b04121b85a524f9f57498e9739e98 to your computer and use it in GitHub Desktop.
GET URL PARAMETER
// GET URL PARAMETER
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];
}
}
};
And this is how you can use this function assuming the URL is,
http://dummy.com/?technology=jquery&blog=jquerybyexample.
var tech = getUrlParameter('technology');
var blog = getUrlParameter('blog');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment