如何在Firefox中打开子窗口时自动关闭父窗口
我有此代码需要在打开子窗口时关闭parent.html窗口,我需要在IE和Firefox中运行良好的代码如何在Firefox中打开子窗口时自动关闭父窗口
Parent.html
<HTML>
<SCRIPT TYPE="text/javascript">
function sendTo()
{
window.open('child.html','_blank','resizable=yes,width='+(screen.width-500)+',height='+(screen.height-500)+'');
}
</SCRIPT>
<BODY>
<form name="form">
<input type="text" value="" name="text1" id="pdetails1">
<input type="text" value="" name="text1" id="pdetails2">
</br>
<input type="submit" value="submit" onClick="sendTo()">
</BODY>
</HTML>
child.html
<html>
<body>
<form>
<input type=text name="text5" value="">
<input type=submit name="submit"value="submit">
</form>
</body>
</html>
:
<script type="text/javascript">
window.opener.close();
</script>
但是,大多数浏览器不会让你。
不,在Firefox中显示错误消息脚本可能没有关闭未被脚本打开的窗口 – Prabakaran 2011-03-24 04:19:04
正如我所说的,大多数浏览器都不会让你。你总是可以在'window.open(...' – 2011-03-24 04:22:04
试试这个
父窗口:
<script type="text/javascript">
function sendTo()
{
window.open('child.html','_blank','resizable=yes,width='+(screen.width-500)+',height='+(screen.height-500)+'');
this.window.close();
}
</SCRIPT>
OR 在子窗口
<script type="text/javascript">
window.opener.close()
</SCRIPT>
第1步:输入在地址栏中显示为 “about:config中”,然后按回车键
第2步:“我会小心,我保证”点击此按钮
第3步:“dom.allow_scripts_to_close_windows”搜索此行并双击它。
)后面加上'window.close()',不能指望呼叫用户启用它。 – 2014-09-16 05:33:41
做到这一点。首先打开当前窗口,以欺骗当前标签,认为它已被脚本打开。然后使用window.close()关闭它。下面的脚本应该进入父窗口,而不是子窗口。在运行脚本打开孩子之后,您可以运行它。
<script type="text/javascript">
window.open('','_parent','');
window.close();
</script>
当你有一个适合你的答案时,你应该接受它作为答案。 – 2011-03-24 04:09:48