简体   繁体   English

在Window.Open之后,JavaScript setTimeout没有触发

[英]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. 我有一个ASP.Net网页,目前适用于iOS4但不适用于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. 然后我在打开窗口调用后立即在父窗口中执行setTimeout刷新。

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. 我在iPhone iOS5上注意到,当它打开子窗口时,父窗口中的setTimeout函数不会被调用,直到我回到父窗口然后返回到子窗口才能看到更新。

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. 这适用于iOS4,但不适用于iOS5。

Any ideas? 有任何想法吗?

iOS5 does indeed pause JavaScript when a window is not the active window. 当窗口不是活动窗口时,iOS5确实会暂停JavaScript。 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. 关于此,您无能为力,因此您可以做的最好的方法是尝试更改您的设置,以便在窗口处于后台时不需要运行JavaScript。

You said you are doing a setTimeout refresh thing in the parent window . 你说你setTimeout refresh thing in the parent window中做了一个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(); 该行究竟handles[0].testfx();什么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 . 这只是一个建议,因为我无权测试这个,但你可以通过使用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. 在您的情况下,您可能想要检查是否已经过了所需的时间量,如果没有,请再次调用window.postMessage ,否则,请调用您的处理程序。

I'm not sure how quickly calls to window.postMessage will be processed, if at all, when not in the active window. 我不确定对window.postMessage调用是否会被快速处理,如果有的话,不在活动窗口中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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