阻止在iPad任务切换上重新启动Web应用程序 [英] Prevent web app restart on iPad task switch

查看:188
本文介绍了阻止在iPad任务切换上重新启动Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPad上运行了一个网络应用程序。它以全屏模式运行。如果我的任务切换到另一个应用程序(通过双击主页按钮等),然后切换回我的网络应用程序,然后我的网络应用程序重新启动。

I have a web app running on an iPad. It is running in full-screen mode. If I task switch to another app (by double-clicking the home button etc), then switch back to my web app, then my web app restarts.

有没有在iPad任务切换后收到焦点时阻止Web应用程序重新启动的方法?显然,我只是希望它能够在失去焦点的状态下完全呈现出来。

Is there any way to prevent the web app from restarting when it receives the focus after an iPad task switch? Obviously I just want it to show itself in exactly the state it was in when it lost focus.

谢谢。

推荐答案

不,这是不可能的。

最好的行动方式是将状态保存到localStorage。如果你正在使用eg。用于跟踪状态的URL哈希(例如myApp.html / #logateScreen),可以存储该信息,然后将其应用于location.hash,这将调度window.onhashchange。

The best way to act is to save a state into localStorage. If you're using eg. URL hash for tracking your state (eg. myApp.html/#loginScreen), one can store that info and then apply it on location.hash which would dispatch window.onhashchange.

换句话说(代码只是在飞行中写的示例):

In other words (codes are just example written on fly):

1 - 将相关信息存储到localStorage:

1 - store relevant information to localStorage:

localStorage.setItem("state", "loginScreen");

2 - 在启动时检索值并将其应用于哈希:

2 - retrieve value on start up and apply it to hash:

location.hash = (localStorage.getItem("state")) ? localStorage.getItem("state") : "";

3 - 将事件监听器绑定到onhashchange并从那里继续:

3 - bind an event listener to onhashchange and proceed from there:

window.addEventListener("hashchange", function() {
    if (location.hash.length) {
        alert("Current state of UI is :"+ location.hash);
    }   
}, false);

这篇关于阻止在iPad任务切换上重新启动Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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