Skip to content

Instantly share code, notes, and snippets.

@willwm
Last active April 15, 2018 11:40
Show Gist options
  • Save willwm/e3929240b3413fa7703eb66f2ef5c1f1 to your computer and use it in GitHub Desktop.
Save willwm/e3929240b3413fa7703eb66f2ef5c1f1 to your computer and use it in GitHub Desktop.
Retrieve the value associated with 'key' from window.location.hash
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
function getHashValueForKey(key) {
var hash = window.location.hash.substr(1);
var searchParams = new URLSearchParams(hash);
return searchParams.get(key);
}
@willwm
Copy link
Author

willwm commented Nov 22, 2017

Example:

https://example.com#key1=value1&key2=value2

getHashValueForKey("key1"); // returns "value1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment