gpt4 book ai didi

Javascript 打开弹出窗口并禁用父窗口

转载 作者:行者123 更新时间:2023-12-02 23:53:09 24 4
gpt4 key购买 nike

我想打开一个弹出窗口并禁用父窗口。下面是我正在使用的代码;

function popup()
{

popupWindow = window.open('child_page.html','name','width=200,height=200');
popupWindow.focus();
}

由于某种原因,父窗口不会被禁用。我需要一些额外的代码还是什么情况?

再次,我正在寻找与使用 showModalDialog() 时得到的类似的东西......即它根本不允许选择父窗口。唯一的事情是我想使用 window.open 完成同样的事情

还请建议跨浏览器兼容的代码..

最佳答案

var popupWindow=null;

function popup()
{
popupWindow = window.open('child_page.html','name','width=200,height=200');
}

function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}

然后在父窗口的body标签中声明这些函数

<body onFocus="parent_disable();" onclick="parent_disable();">

根据您的要求,这里是父窗口的完整 html 代码

<html>
<head>
<script type="text/javascript">

var popupWindow=null;

function child_open()
{

popupWindow =window.open('new.jsp',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");

}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<a href="javascript:child_open()">Click me</a>
</body>
</html>

下面new.jsp的内容

<html>
<body>
I am child
</body>
</html>

关于Javascript 打开弹出窗口并禁用父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5660700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com