Javascript / jQuery仅在浏览器后退/前进按钮单击时检测哈希更改 [英] Javascript/jQuery detect hash change only on browser back/forward button click

查看:128
本文介绍了Javascript / jQuery仅在浏览器后退/前进按钮单击时检测哈希更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅在浏览器历史记录更改(即后退或前进按钮)上检测哈希更改?

Is it possible to detect the hashchange only on a browser history change (i.e. Back or Forward button)?

我看过onBeforeUnload事件,但此事件确实如此因为窗口没有卸载,所以不会激活散列更改。

I have seen the onBeforeUnload event, but this event does not fire on hash change, as the window is not unloading.

散列事件显然会随着散列更改而触发。任何修复?优选地,没有插件。我已经看过jQuery历史插件,但我正在寻找最简单的解决方案。

The hashchange event obviously fires anytime the hash changes. Any fix? Preferably without a plugin. I have seen the jQuery history plugin, but am looking for the simplest solution.

感谢您的帮助。

推荐答案

查看 window.onhashchange event。

但是目前并不支持所有浏览器。在这里查看BA jQuery Hash Change Plugin。如果您最终选择使用插件,它可能会有效。

It is not currently supported in all browsers however. Take a look at the BA jQuery Hash Change Plugin here. It may work, if you choose to use a plugin in the end.

我希望这会有所帮助!

这篇关于Javascript / jQuery仅在浏览器后退/前进按钮单击时检测哈希更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆