3

I'm using window.onhashchange to detect browser hash changes. But is there a way to only trigger the callback if the hash was changed in a non-programmatic way?

I am not asking how to use onhashchange. I am trying to avoid triggering it when I set the hash programmatically.

Basically, I want to do something similar to:

window.onhashchange = () => { /* ... */ };

But I don't want the callback to trigger if the code did the following:

window.location.hash = 'hello-world';    

Thanks!

Max
  • 1,399
  • 13
  • 28
  • 1
    Possible duplicate of [On - window.location.hash - change?](http://stackoverflow.com/questions/680785/on-window-location-hash-change) – technico Aug 06 '16 at 05:22
  • 3
    Not the same question. – Max Aug 06 '16 at 06:53
  • Have you solved it? Lately so became place that doesn't give answers to hard questions. Can you at least tell me how you solved it??? – hackp0int Dec 11 '16 at 18:08

1 Answers1

1

I ended up solving it by simply setting a flag, which seems like a hack, but given JavaScript execution environments are single-threaded, should work fine.

Max
  • 1,399
  • 13
  • 28