Reputation: 1673
Is it possible to close a modal window from it's parent? It is a little hard even to try to do this. Basically, I am opening a non-modal window. From that non-modal window the user might some times open a modal window. Now suppose I close the non-modal window... I would like the modal subwindow to close also. How can this be done?
Basically, overall, I have to find a way to close a modal window from it's parent.
Thanks, Grae
Here is some code to give you a sample.
The Start Page
<html>
<head>
<script>
window.childWindow;
function openNonModal()
{
window.childWindow = window.open("nonmodal.html","_blank", "dialogWidth=500px;dialogHeight=294px;scroll=no;status=no;caption=no;titlebar=no;menubar=no;toolbar=no;help=no");
setTimeout("closeChildWindow()",5000);
}
function closeChildWindow()
{
window.childWindow.closeChildWindow();
window.childWindow.close();
}
<script>
</head>
<input type="button" value="openNonModal" onclick="openNonModal(); return false;"/>
</html>
The nonModal window which open a modal window.
<html>
<head>
<script>
function openModal()
{
var retVal = window.showModalDialog("modal.html","_blank", "dialogWidth=500px;dialogHeight=294px;scroll=no;status=no;caption=no;titlebar=no;menubar=no;toolbar=no;help=no");
}
function closeChildWindow()
{
alert("should close child window");
}
</script>
</head>
<input type="button" value="openModal" onclick="openModal(); return false;"/>
</html>
The window that is modal is just text.
<html>
Just a sample.
</html>
Upvotes: 3
Views: 5065
Reputation: 1961
As soon as you open a modal window, the opener freezes and you can't apply any control via it!
for more clarification take a look on this code:
setTimeout('alert(1);', 1000);
setTimeout('alert(2);', 2000);
setTimeout('window.showModalDialog(...);', 3000);
setTimeout('alert(3);', 4000);
alert(1)
will be executed on the first second.
alert(2)
will be executed on the next second even if you don't confirm the alert(1)
.
on the 3rd second the modal window will be opened and at this point the opener window freezes, so alert(3)
will not be executed on the 4th second.
alert(3)
wont be executed when the modal window is still open, but one second after closing the modal window, alert(3)
will be executed.
Conclusion: Parent has no control on the modal window after opening, because it's actually dead :-(
Upvotes: 2