本文介绍了如何使用javascript检测iPhone / Android从睡眠状态唤醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用sockets.io的网站/ webapp

Im building a website/webapp that uses sockets.io

目前,如果用户在iphone上使用safari,他们会锁定屏幕(变黑)我的套接字连接已关闭。这很好,我想要这个。

Currently if the user is using safari on an iphone for example and they lock the screen (goes black) My socket connection is closed. This is good, I want this.

然而,当他们解锁屏幕(或从睡眠中醒来)。我想用javascript检测这个事件,所以我可以重新连接我的套接字。

However when they unlock the screen (or awake from sleep). I would like to detect this event with javascript so I can reconnect my socket.

这可能吗?谷歌在这个问题上没有太多关注。

Is this possible?? Google isn't turning much up on the subject.

推荐答案

没关系,我想出来了

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

这篇关于如何使用javascript检测iPhone / Android从睡眠状态唤醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:03
查看更多