I noticed that YouTube doesn't actually reload when you click a link/video on their website. If you define a variable in the console you'll see it will persist.
But neither popstate
nor beforeunload
get fired. So how is Youtube accomplishing that? And how can I detect that URL change without making a timer constantly check the URL bar.
window.onpopstate = function(event) {
console.log('popstate test!')
return "test"
}
window.onbeforeunload = function(event) {
console.log('beforeunload test!')
return "test"
}
I'm not just looking for a YouTube-solution, I'm looking for a general solution that covers the technology YouTube is using.