iPhone上不支持onbeforeunload事件吗? [英] Is the onbeforeunload event not supported on iPhone?

查看:1652
本文介绍了iPhone上不支持onbeforeunload事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在jQuery Mobile应用程序中有一些方便的功能,让用户知道他/她是否正在离开页面,因为这会触发注销。简化形式:

So, I've got a handy little bit of functionality in place in a jQuery Mobile app that lets the user know if he/she is navigating away from the page, as this will trigger a log off. In simplified form:

$(window).bind('beforeunload', function() {
  return "Navigating away from this page will log you off. Are you sure you want to continue?";
});

$(window).unload(function() {
  logoff();
});

这在我的笔记本电脑上的Safari和Chrome中都很棒。但是,它似乎无法在iPhone模拟器上运行。

This works just great in both Safari and Chrome on my laptop. However, it doesn't appear to work on the iPhone simulator.

移动浏览器是否包含在iOS中(我知道它是Safari,但可能是不同的版本)根本没有支持 beforeunload 事件?这对于移动设备(特别是Android)来说是否正确?

Does the mobile browser included in iOS (I know it's Safari, but presumably a different version) simply not support the beforeunload event? Is this true in general for mobile devices (in particular, Android)?

推荐答案

iPhone确实不支持 onbeforeunload

The iPhone indeed does not support onbeforeunload

这个问题有一个可能的解决方法:
有没有办法在Mobile Safari for iOS设备上使用window.onbeforeunload?

This question has a possible workaround: Is there any way to use window.onbeforeunload on Mobile Safari for iOS devices?

这篇关于iPhone上不支持onbeforeunload事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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