开发者

onhashchange reloads page?

开发者 https://www.devze.com 2023-03-03 20:33 出处:网络
Is that correct? I was thinking it was just an event that fired when the page refreshed. I did a basic document.write and did i++ whenever onhashchange was triggered but it always is at 0 and i lose a

Is that correct? I was thinking it was just an event that fired when the page refreshed. I did a basic document.write and did i++ whenever onhashchange was triggered but it always is at 0 and i lose all my other vars and stuff. I also tried re开发者_Go百科turn false, but nothing.

Am i doing it wrong? Or is onhashchange supposed to reset the page? If so, can you stop it but still fire the callback?


No onHashChange merely fires whenever the # portion of a url is changed, this is client-side only and the page should not reload when doing so. document.write however can clobber your global variables.

If you need more help we'll need more to go on.


It looks like the problem is that Web Inspector is super buggy with this. For example, multiple console.log()s in a onhashchange rewrite the same console.log(). Also, i noticed that sometimes the console would just go completely blank when changing pages. I discovered it's bugginess when I put a timer on the page and noticed the timer was incrementing but the console was showing blank or misinformation.

0

精彩评论

暂无评论...
验证码 换一张
取 消