简体   繁体   English

我怎么知道location.reload()何时完成?

[英]how do i know when location.reload() finishes?

i have a frame that i want to reload, resetting all values and content of the page, but the root page continues with running scripts. 我有一个要重新加载的页面,重置页面的所有值和内容,但根页面继续运行脚本。 The issue with that is that in the time it takes for the page to reload, requests are sent to the pages javascript, causing errors as resources are not loaded. 这样做的问题是,在重新加载页面所需的时间中,请求已发送到页面javascript,因为未加载资源而导致错误。

top.document.getElementById("designer").contentWindow.location.reload()
top.document.getElementById("designer").contentWindow.getCSS()

So as you can see here, the page might not be reloaded in time, so how would i resolve this? 因此,正如您在这里看到的那样,该页面可能未及时重新加载,那么我该如何解决呢?

is there a way to pause javascript execution until location.reload() returns true or something? 有没有办法暂停JavaScript执行,直到location.reload()返回true或其他内容?

You can set up onload handler for your iframe so that your reload doesnt trigger 您可以为iframe设置onload处理程序,以免触发reload

Sample code:- 示例代码:-

function Test() {

    iframe = document.getElementById('ABCD');
    iframe.onload = function() {
        location.reload(true);
    }
    //.... 
}

or if you want to add some time delay then try like this:- 或者,如果您想增加一些延迟,请尝试执行以下操作:-

function Test() {
    iframe = document.getElementById('ABCD');
    iframe.onload = function() {
        setTimeout(function() {location.reload(true)}, 5000);
    }
    //....
}

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

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