简体   繁体   中英

JavaScript setTimeout not firing after Window.Open

I have an ASP.Net web page that currently works on the iOS4 but not on the iOS5.

On the parent web page I have a button that opens a child window. And I do a setTimeout refresh thing in the parent window right after the open window call.

I noticed on the iPhone iOS5 that when it opens the child window, the setTimeout function in the parent page is not called until I go back to the parent window and then back to the child window to see the update.

Here's a snippet of my code in the parent page and where I think is the problem

WindowManager.OpenWindow('...')
t = setTimeout(function() { handles[0].testfx(); }, 1000);

this runs on iOS4 but not on iOS5.

Any ideas?

iOS5 does indeed pause JavaScript when a window is not the active window. There is nothing you can do about this, so the best you can do is try to alter your setup so that JavaScript does not need to be run when your window is in the background.

You said you are doing a setTimeout refresh thing in the parent window . WHY are you doing this? Frankly, it sounds a little bit odd -- why do you want to be refreshing anything when the user can't even see your page? What exactly does the line handles[0].testfx(); do for you?

This is just a suggestion, since I don't have access to test this, but you may be able to hack around this using by using window.postMessage . An example of this can be found here .

In your case, you would probably want to check if a required amount of time had elapsed, and if not, call window.postMessage again, otherwise, call your handler.

I'm not sure how quickly calls to window.postMessage will be processed, if at all, when not in the active window.

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