简体   繁体   English

“提问”中的后退按钮事件捕获

[英]Back button event capturing in “Ask Question”

The back button event isn't captured by window.onbeforeunload and isn't being handled by the onbeforeunload handler. window.onbeforeunload不捕获后退按钮事件,并且onbeforeunload处理程序不处理。

There are a few questions on SO asking about capturing the back button with no good answer but yet if a user hits the browser's back button while composing a new question on SO a message box asking him to if he's sure he wants to continue pops-up. 关于捕获后退按钮没有什么好答案的问题有一些问题,但是如果用户点击浏览器的后退按钮同时在SO上创建一个新问题则询问他是否确定他想要继续弹出。

This message box is different between Chrome and FF and feels native. 此消息框在Chrome和FF之间有所不同,并且感觉很原生。

So, what's behind the curtains? 窗帘背后是什么?

How can I have the browser popup a message box which gives the user the option to stay on the current page (like with onbeforeunload )? 如何让浏览器弹出一个消息框,让用户可以选择保留当前页面(如onbeforeunload )?

The back button event isn't captured by window.onbeforeunload and isn't being handled by the onbeforeunload handler. window.onbeforeunload不捕获后退按钮事件,并且onbeforeunload处理程序不处理。

Not true. 不对。 Check this test case with plain JavaScript - back button triggers the onbeforeunload just fine. 使用纯JavaScript检查此测试用例 - 后退按钮触发onbeforeunload就好了。 Checked with recent versions of all major browsers: Chrome 18, Firefox 11 and IE9. 查看了所有主流浏览器的最新版本:Chrome 18,Firefox 11和IE9。 (Copy the link address, browse first to some other site then to the fiddle and hit the Back button) (复制链接地址,首先浏览到其他网站然后到小提琴,然后点击返回按钮)

So I fear your question is not really relevant - what you see is the browser native dialog. 所以我担心你的问题并不真正相关 - 你看到的浏览器原生对话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM