Skip to content

Instantly share code, notes, and snippets.

@sr9yar
Last active August 17, 2020 06:10
Show Gist options
  • Save sr9yar/2af4630f0a9538e373fd8b28be89d836 to your computer and use it in GitHub Desktop.
Save sr9yar/2af4630f0a9538e373fd8b28be89d836 to your computer and use it in GitHub Desktop.
Detect Location Change
var oldHref = document.location.href;
window.onload = function() {
var bodyList = document.querySelector("body");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
console.log("LOCATION CHANGE:", oldHref);
}
});
});
var config = {
childList: true,
subtree: true
};
observer.observe(bodyList, config);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment