: A countdown is done on a page, and then the user wants to leave the page to do other things, the requirement is to leave the page after the time to save, the next time to come in and continue the time of the last left
The first time I used the event was://window.onbeforeunload = function () {... However, iOS mobile does not have any reaction, that is, incompatible.
The second time I used: Window.addeventlistener (' Pagehide ', function () {...}) Perfect solution.
- onBeforeUnload supported mobile browsers see Windoweventhandlers/onbeforeunload
- Available for Safari browser
pagehide , see Handling Events
Window.addeventlistener (' Pagehide ',function () { //Localstorage.setitem ("Selftestid", Selftestid); //Localstorage.setitem ("Remainderlength", remainderlength);Console.log (Selftestid) console.log (remainderlength) $.ajax ({type:' Post ', URL:"...", type:' Post ', Async:false, data: {key:key, Id:selftestid, Remainderlength:remainderlength//Time Storage Backend}, DataType:' JSON ', Success:function(Result) {Console.log (result); } }) // }});
Here my original idea is to put in the local storage, but later I think if the user in this operation of the page and the next operation of the phone if not the same, then is not the local storage of content, so there is a server
PC-side pages, mobile Web pages (Andorid, iOS) leave the page to do a time storage