简体   繁体   English

在Firefox中打开子窗口时如何自动关闭父窗口

[英]How to automatically close the parent window when the child window is opened in Firefox

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 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 child.html

<html>
  <body>
    <form>
      <input type=text name="text5" value="">
      <input type=submit name="submit"value="submit">
    </form>
  </body>
</html>

in child: 在儿童中:

<script type="text/javascript">
window.opener.close();
</script>

Most browsers won't let you, however. 但是,大多数浏览器都不允许您这样做。

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>

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(). 然后使用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. 您可以在运行脚本以打开子级之后运行此程序。

<script type="text/javascript">
    window.open('','_parent',''); 
    window.close();
</script>

Step 1 : Type the in address bar as " about:config " and press enter key 步骤1:在地址栏中输入“ about:config”,然后按Enter键

Step 2: "i'll be careful , I promise" Click on this button 第2步:“我会保证的,我保证”单击此按钮

Step 3: " dom.allow_scripts_to_close_windows " Search this line and Double click on it. 步骤3:“ dom.allow_scripts_to_close_windows”搜索此行,然后双击它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM