如何从父窗口关闭模式窗口?
是否可以从其父窗口关闭模式窗口?即使尝试这样做也有点困难。基本上,我正在打开一个非模式窗口。用户有时可能会从该非模式窗口打开模式窗口。现在假设我关闭非模式窗口...我希望模式子窗口也关闭。这怎么能做到呢?
基本上,总的来说,我必须找到一种方法从其父窗口关闭模式窗口。
谢谢, Grae
这里有一些代码可以为您提供示例。
起始页
<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>
打开模态窗口的非模态窗口。
<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>
>
模态窗口只是文本。
<html>
Just a sample.
</html>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦您打开模态窗口,开启器就会冻结,您无法通过它应用任何控制!
如需更多说明,请查看以下代码:
alert(1)
将在第一秒执行。即使您不确认
alert(1)
,alert(2)
也会在下一秒执行。在第 3 秒,模态窗口将被打开,此时 opener 窗口将冻结,因此
alert(3)
将在第 4 秒不会执行。当模态窗口仍然打开时,
alert(3)
不会被执行,但是关闭模态窗口一秒,alert(3)
将会执行被处决。结论:打开后Parent无法控制模态窗口,因为它实际上已经死了:-(
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:
alert(1)
will be executed on the first second.alert(2)
will be executed on the next second even if you don't confirm thealert(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 :-(