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.
打开模态窗口的nonModal窗口。
<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>
1 个解决方案
#1
2
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(1)将在第一秒执行。
alert(2)
will be executed on the next second even if you don't confirm the alert(1)
.
即使您没有确认警报(1),警报(2)也会在下一秒执行。
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.
在第3秒,模态窗口将被打开,此时开启窗口冻结,因此警报(3)将不会在第4秒执行。
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.
alert(3)当模态窗口仍然打开时不会执行,但在关闭模态窗口后一秒钟,将执行alert(3)。
Conclusion: Parent has no control on the modal window after opening, because it's actually dead :-(
结论:父母在打开后无法控制模态窗口,因为它实际上已经死了:-(
#1
2
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(1)将在第一秒执行。
alert(2)
will be executed on the next second even if you don't confirm the alert(1)
.
即使您没有确认警报(1),警报(2)也会在下一秒执行。
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.
在第3秒,模态窗口将被打开,此时开启窗口冻结,因此警报(3)将不会在第4秒执行。
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.
alert(3)当模态窗口仍然打开时不会执行,但在关闭模态窗口后一秒钟,将执行alert(3)。
Conclusion: Parent has no control on the modal window after opening, because it's actually dead :-(
结论:父母在打开后无法控制模态窗口,因为它实际上已经死了:-(