当WebKit WebApp被“终止”时,会触发什么事件。 [英] What event fires when a WebKit WebApp is "terminated"

查看:177
本文介绍了当WebKit WebApp被“终止”时,会触发什么事件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS开发Web应用程序并使用DOMApplicationCache。我知道Web Apps无法在后台运行,但是当用户切换到另一个应用程序并稍后返回到Web应用程序时,我仍然希望模拟应用程序的简历。

I am in the process of developing a Web App for iOS and am using the DOMApplicationCache. I know that Web Apps can not run in the background, but I still would like to simulate a resume of the app when the user switches to another app and returns to the web app later.

为了做到这一点,我至少需要记录Web App终止/卸载的时间。但是window.unload似乎没有激发。

In order to do this I at least need to record when the Web App terminates/unloads. But the window.unload does not seem to fire.

有没有人知道如何捕获正在运行的WebApp的终止?

Does anybody have an idea how to catch the termination of a WebApp running?

PS:在一个相关的问题上,当apple-mobile-web-app-capable是的时,console.log会去哪里?

PS: on a related question, where does the console.log go when apple-mobile-web-app-capable is yes?

推荐答案

您可以使用pageshow事件来检测应用程序何时恢复。当用户从其他的Safari选项卡返回您的应用时,此事件将触发。当用户点击主页按钮然后通过单击safari按钮返回应用程序时它也会触发

You can use the "pageshow" event to detect when the app has resumed. This event will fire when user returns to your app from a different safari tab. It will also fire when user clicks the home button and then comes back to the app by clicking on safari button

     <script>
    window.addEventListener("pageshow", function(){
        alert("page shown");
    }, false);
  </script>

我已经在iOS模拟器上对其进行了测试,其工作情况如上所述。

I have tested this on the iOS simulator and its working as I described above.

这篇关于当WebKit WebApp被“终止”时,会触发什么事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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