Cloud Man
Cloud Man

Reputation: 101

Javascript SetInterval Not Working in IE

I am using window.open to open a popup window and setinterval function to wait and refresh the background page, once the popup is closed. the code is working fine in Chrome and Firefox but is not working in IE.

Basically the issue is: in IE, it doesn't wait until popup window is closed. It immediately gets refreshed as soon as the popup opens up. I saw the issue coming in both IE 9 & IE 11.

Any solution for this?

This is the code:

var url = "/apex/VFP_Add";
var win = window.open(url, "Add" ,"width=600, height=300, scrollbars=yes"); 
win.moveTo(500, 100); 
win.focus(); 
var timer = setInterval(function() { 
if(win.closed) { 
clearInterval(timer); 
window.location.reload(); 
} 
}, 500);

I put alerts just before if(win.closed) check and just after the check. For the first alert, it showed as False. In second alert, after "if check", it showed True. This is very weird because i had not closed the window.

Upvotes: 0

Views: 2039

Answers (1)

zaparker
zaparker

Reputation: 485

It seems that's a known bug in IE. See this article about it: https://support.microsoft.com/en-us/kb/241109

Their solution is to basically negate the value of win.closed when you detect that it's running in IE. Something like:

if(win.closed || isRunningInIE()) {
    clearInterval(timer); 
    window.location.reload(); 
}

There are different ways to detect IE, so you can just use your favorite method in place of that isRunningInIE() function.

Upvotes: 1

Related Questions