简体   繁体   中英

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.

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?

You can set up onload handler for your iframe so that your reload doesnt trigger

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);
    }
    //....
}

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