在iPad上运行时,Mobile Safari中即将进行的选项卡切换的Pagehide事件不会触发 [英] Pagehide event on imminent tab switching in Mobile Safari does not fire when running on iPad

查看:434
本文介绍了在iPad上运行时,Mobile Safari中即将进行的选项卡切换的Pagehide事件不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,Mobile Safari会暂停在网页上执行Javascript

It is well know that Mobile Safari pauses Javascript execution on a webpage when


  1. 您切换到其他浏览器标签

  2. 切换到另一个iOS应用程序(例如,当您接到来电的电话应用程序时)

您可以订阅到窗口的pagehidepageshow事件,以检测即将暂停和重新激活Javascript。

You can subscribe to the window's "pagehide" and "pageshow" events to detect imminent suspension and reactivation of Javascript.

问题是,在 iPad 移动版Safari上标签切换(1.)时,这些事件不会触发。在 iPhone 移动版Safari上,一切都正常,如上所述。

The problem is, those events do not fire when tab-switching (1.) on an iPad Mobile Safari. On an iPhone Mobile Safari everything is fine, just as described above.

展示这一点很简单:

<!DOCTYPE html>
<html>
<head>
    <script>
        window.addEventListener("pagehide", function(evt){
            var logger = document.getElementById('log_id');
            logger.innerText = logger.innerText + " pagehide fired!";
        }, false);
    </script>
</head>
<body>
<div id="log_id"></div>
</body>
</html>

仅在进行应用程序切换(2.)时才会在iPad(iOS5和iOS6 Preview3)上触发不在制表符切换(1.)上。所有iPhone工作正常..

It fires on iPads (iOS5 and iOS6 Preview3) only when doing app-switching (2.) and not on tab-switching (1.). All iPhones work fine..

有没有人能够在iPad浏览器上检测到即将发生的标签切换?

Has anyone been able to detect an imminent tab-switching on the iPad browser?

当标签再次变为活动状态时,Javascript的重新激活可以通过心跳循环检测到,如对同一主题的讨论

The reactivation of Javascript when the tab becomes active again can be detected by a heart beat loop as described in this discussion of the same topic.

推荐答案

Apple在 iOS7 中修复。
(刚刚在iPad模拟器中尝试过)

Fixed by Apple in iOS7. (Just tried in the iPad Simulator)

这篇关于在iPad上运行时,Mobile Safari中即将进行的选项卡切换的Pagehide事件不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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