PC-side pages, mobile Web pages (Andorid, iOS) leave the page to do a time storage

Source: Internet
Author: User

: 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.