DEV Community

Discussion on: DEV zen mode: userscript

Collapse
 
shindakun profile image
Steve Layton • Edited

My understanding is that window.onhashchange() is only really going to see changes to location.hash and not all URL changes. So if we click on an anchor link and go from https://dev.to to https://dev.to#something the location.hash becomes #something. A quick example that can be pasted in the console is:

function hashHandler() {
  console.log("The hash has changed! It's now " + location.hash);
}

window.addEventListener('hashchange', hashHandler, false);

Then just throw a #hash in the address bar and hit enter.

Collapse
 
detunized profile image
Dmitry Yakimenko

I thought so. The names kinda gives it away, doesn't i? But I was confused by what I read online. It seemed like it's supposed to fire on any URL change. Oh, well. Next time better luck.