是否有另一种方法可以在移动旅行中使用onbeforeunload? [英] Is there an alternative method to use onbeforeunload in mobile safari?

查看:84
本文介绍了是否有另一种方法可以在移动旅行中使用onbeforeunload?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mobile-safari中是否有替代onbeforeunload的替代方法?我注意到Google能够在mobile-safari中捕获 onbeforeunload 事件。有没有人想出他们是如何做到的?

Is there an alternative method to use instead of onbeforeunload in mobile-safari? I've noticed that Google was able to capture the onbeforeunload event in mobile-safari. Has anyone figured out how they are doing so?

谷歌能够使用他们的Gmail客户端这样做。创建新消息...在文本区域中键入内容...点击浏览器后退按钮。它弹出一条警告信息。我使用iPad进行测试。

Google was able to do so using their gmail client. Create a new message... type something in the text area... hit the browser back button. It pops up a warning message. I used an iPad to do my test.

推荐答案

我猜他们正在使用History API。通过收听popstate

I would guess that they are using the History API. By listening to popstate

window.addEventListener("popstate", function(e) { ... });

你可以在允许做任何愚蠢行为之前显示警告。

you can show a warning before allowing doing anything stupid.

这篇关于是否有另一种方法可以在移动旅行中使用onbeforeunload?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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