Skip to content

Instantly share code, notes, and snippets.

@jarrettmeyer
Last active March 14, 2019 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarrettmeyer/d7ed96645c403b270609e73ec8c8f8c6 to your computer and use it in GitHub Desktop.
Save jarrettmeyer/d7ed96645c403b270609e73ec8c8f8c6 to your computer and use it in GitHub Desktop.
Getting URL query values
// Get the parameters after the question mark.
let search = new URLSearchParams(window.location.search);
// Get the token and make sure it matches.
let token = search.get("token");
if (token !== "hello-world") {
// The token did not match what we expected. Get rid of everything out of the body and stop the program.
let body = document.getElementsByTagName("body")[0];
body.style.backgroundColor = "black";
body.innerHTML = '<p style="color: darkred;font-size: 36px;margin: 16px;">Forbidden!</p>';
throw Error("Forbidden!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment