如何捕获在JavaScript浏览器的后退/前进按钮单击事件或哈希改变事件? [英] How to capture browser's back/forward button click event or hash change event in javascript?

查看:504
本文介绍了如何捕获在JavaScript浏览器的后退/前进按钮单击事件或哈希改变事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想警报()点击或哈希以JavaScript改变浏览器的前进或后退按钮时。我曾尝试<一个href=\"http://stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript/136965#136965\">this解决方案,这是工作,但它造成在网页上其他环节的问题,两次提交上的任何链接点击事件的每个请求。

I want to alert() when browser's back or forward button is clicked or hash is changed in javascript. I have tried this solution and it is working but it is causing problems on other links in webpage and submit each request twice on any link click event.

有没有什么解决办法捕捉到它,而无需使用的setInterval()功能?所以,我需要捕获散更改后退/前进按钮单击事件?我需要一个简单的JavaScript code /功能/性能应在所有现代浏览器。

Is there any solution to capture it without using setInterval() function? So I need to capture hash change or back/forward button click event? I need a simple javascript code/function/property that should work in all modern browsers.

任何解决方案?

感谢

推荐答案

可以解释,而这背后的原因何在呢?我们都在下跌preventing后卫/前锋和类似与浏览器功能重整。

Not a good idea

Can you rather explain the reasoning behind this? We've all been down this road of preventing backs/forwards and similar and mangling with browser functionality.

原来,虽然它是更好地服从于浏览器和写入以这种方式让这些事情变得无关紧要您的应用程序。而且这也是事实浏览器锁定的东西越来越多客户端的JavaScript应用程序,因此极有可能您的应用程序会后(少数)浏览器升级失败。

It turns out though it's better to obey to browser and write your application in that way so these things become irrelevant. And it's also true that browsers are locking more and more things to client javascript apps so it's highly likely your app is going to fail after (few) browser upgrades.

HTML5规范的历史可能正是你追求的。这是事物的方式应该工作,并且对于Ajax应用程序来完成,并browser0s前进/后退功能。我建议你​​看看。看到工作演示,这是否相当不错。

HTML5 History spec may be exactly what you're after. It's the way things should work and be done in regard to Ajax applications and browser0s back/forward functionality. I suggest you check it out. See a working demo that does this rather nicely.

这篇关于如何捕获在JavaScript浏览器的后退/前进按钮单击事件或哈希改变事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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