I opened an external url (google.com) using windows.open(). Now the windows object (myWindows) is null, and hence I cant close the popup. Even if it is closed manually, I cant check through code if the popup has been closed.
One workaround is to uncheck the 'Enabled Protected Mode' in internet options. But that isn't a feasible solution. I suppose the issue is due to cross-origin restrictions in IE.
<!DOCTYPE html>
<html>
<head>
<script>
var myWindow = {};
function openWin() {
myWindow = window.open("http://www.google.com", "myWindow", "width=400, height=200");
}
function closeWin() {
if (myWindow) {
myWindow.close();
}
}
function checkWin() {
if (!myWindow) {
document.getElementById("msg").innerHTML = "'myWindow' has never been opened!";
} else {
if (myWindow.closed) {
document.getElementById("msg").innerHTML = "'myWindow' has been closed!";
} else {
document.getElementById("msg").innerHTML = "'myWindow' has not been closed!";
}
}
}
</script>
</head>
<body>
<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>
<br><br>
<button onclick="checkWin()">Has "myWindow" been closed?</button>
<br><br>
<div id="msg"></div>
</body>
</html>
The requirement is to open a 3rd party url in a popup, and when it is closed, the main program needs to fire some event (say display a message). Any suggestion is welcome.