Last active
August 17, 2020 06:10
-
-
Save sr9yar/2af4630f0a9538e373fd8b28be89d836 to your computer and use it in GitHub Desktop.
Detect Location Change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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