简体   繁体   中英

Mobile WebKit browsers - setTimeout and inactive pages

I have a question regarding how Mobile WebKit browsers (ie Mobile Safari and Android browser) handle setTimeout function when the page becomes inactive and is reactivated again.

Let's assume the page becomes inactive (ie the phone screen goes to 'sleep' / we open another application / we open another webpage), and the setTimeout function should have been activated before the page becomes active again.

Now to me it seems that:

  1. Mobile Safari executes the function as soon as the page is activated
  2. Android browser:
    • might execute the function as usual (ie JavaScript continues running even if the page is inactive)
    • might execute as soon as the page is activated (a la Mobile Safari)
    • might not execute at all

I was wondering if someone knows the exact "rules"?

According to the following question, Android just pauses the runtime, and it continues exactly where it left off when the browser is brought to the foreground.

Android browser javascript events when minimised

Slightly different than what you said about Mobile Safari, but seems like a better approach imho.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM