MAK
MAK

Reputation: 1

Javascript to refresh multiple windows after window.open has run

I have a number of url's for quick testing a REST API that I am running using window.open. to launch each call in a separate window. Each window has a 1 second delay before it opens. However as there is some intermittent latency on the servers I need to refresh the windows after they have run.

I have tried to figure out how to use I tried using both: window.location.reload(true); and setTimeout(refresh, 5000);

But I'm not sure how to get the refresh to work on each window as per below.

This is what I am currently running:

setTimeout(function() {
    myWindow1 = window.open('http://xxx','mywindow1','width=200,height=200'); 
}, 0000);

setTimeout(function() {
    myWindow2 = window.open('http://xxx','mywindow2','width=200,height=200'); 
}, 0000);

setTimeout(function() {
    myWindow3 = window.open('http://xxx','mywindow3','width=200,height=200'); 
}, 0000);

Upvotes: 0

Views: 246

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075785

Because they're cross-origin, you probably can't refresh them.

If you can in your environment, this is how:

myWindow1.reload(true);

...at the time you want it to happen (which is obviously after your timer callback has run and opened the window, so myWindow1 has a value). For instance, if you want to refresh it 20 seconds after you opened it:

setTimeout(function() {
    myWindow1 = window.open('http://xxx','mywindow1','width=200,height=200'); 
    setTimeout(function() {
        myWindow1.reload(true);
    }, 20000);
}, 0000);

Upvotes: 2

Related Questions