javascript 如何在Firefox中打开子窗口时自动关闭父窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5414618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to automatically close the parent window when the child window is opened in Firefox
提问by Prabakaran
i have this code i need to close the parent.html window when the child window opened, i need the code for that working well in IE and Firefox
我有这个代码我需要在子窗口打开时关闭 parent.html 窗口,我需要在 IE 和 Firefox 中运行良好的代码
Parent.html
父.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
<html>
<body>
<form>
<input type=text name="text5" value="">
<input type=submit name="submit"value="submit">
</form>
</body>
</html>
回答by Mark Kahn
in child:
在孩子:
<script type="text/javascript">
window.opener.close();
</script>
Most browsers won't let you, however.
但是,大多数浏览器不会让您这样做。
回答by Gate
try this
试试这个
Parent Window:
父窗口:
<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 In Child window
或 在子窗口中
<script type="text/javascript">
window.opener.close()
</SCRIPT>
回答by Pangamma
Do this. First open the current window to trick your current tab into thinking it has been opened by a script. Then close it using window.close(). The below script should go into the parent window, not the child window. You could run this after running the script to open the child.
做这个。首先打开当前窗口,诱使当前选项卡认为它已被脚本打开。然后使用 window.close() 关闭它。下面的脚本应该进入父窗口,而不是子窗口。您可以在运行脚本后运行它以打开子项。
<script type="text/javascript">
window.open('','_parent','');
window.close();
</script>
回答by Vilas Borate
Step 1 : Type the in address bar as " about:config " and press enter key
第 1 步:在地址栏中输入“about:config”并按回车键
Step 2: "i'll be careful , I promise" Click on this button
第二步:“我会小心的,我保证”点击这个按钮
Step 3: " dom.allow_scripts_to_close_windows " Search this line and Double click on it.
第 3 步:“dom.allow_scripts_to_close_windows”搜索此行并双击它。