Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect iPhone/Android awake from sleep with javascript

Im building a website/webapp that uses sockets.io

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.

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.

like image 871
jennas Avatar asked Feb 19 '12 06:02

jennas


People also ask

How do you detect device is Android or IOS in Javascript?

Get the navigator. userAgent Property in a variable name userAgent. Check for the 'android' in the userAgent by using RegExp. If the value of Android is not 0 then it is android phone else not android phone.

How do I know if my phone is IOS or Android?

On your device, go to the Home screen (the one with all the icons), and tap on the Settings icon. Scroll down and tap on About phone or About tablet. Some information will appear. If one of the lines of information says Android with a version number, you have an Android device.


1 Answers

Nevermind, I figured it out

<script>
window.addEventListener("pageshow", function(){
    alert("page shown");
}, false);
</script>
like image 184
jennas Avatar answered Nov 15 '22 13:11

jennas