Skip to content

Instantly share code, notes, and snippets.

@themegabyte
Last active February 27, 2022 15:29
Show Gist options
  • Save themegabyte/fc87ad5494ca6ea6254aa79e24646c62 to your computer and use it in GitHub Desktop.
Save themegabyte/fc87ad5494ca6ea6254aa79e24646c62 to your computer and use it in GitHub Desktop.
Get a variable from the URL parameters, similar to PHP $_GET
function getQueryVariable(variable) {
var svalue = location.search.match(
new RegExp("[?&]" + variable + "=([^&]*)(&?)", "i")
);
return svalue ? svalue[1] : svalue;
}
// ?page=1
getQueryVariable("page"); // 1
// courtesy: https://css-tricks.com/snippets/javascript/get-url-variables/#comment-63646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment