Skip to content

Instantly share code, notes, and snippets.

@0-Sony
Created January 19, 2018 11:46
Show Gist options
  • Save 0-Sony/571a511b7746fbe9669ff0c1bfd3df82 to your computer and use it in GitHub Desktop.
Save 0-Sony/571a511b7746fbe9669ff0c1bfd3df82 to your computer and use it in GitHub Desktop.
Get url GET parameter value by name, depending on given url
getParameterByName: function (name, url) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(url);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
/** Example : We want to know if a param get "page" exist on our current url **/
var results = getParameterByName('page', window.location);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment