如何关闭父 window?

how to close a parent window?

当我提交表单时,我有一个申请表,它被重定向到 window,其中有选项 "print" 和关闭。

Please click <a  onclick="self.close();" href="#">here</a> to close this window.

如果我点击关闭,选项卡本身会在 chrome 和 IE 中关闭,但它在 Mozilla 中不起作用。

当我使用这段代码时,

Please click <a  onclick="CloseWindow();" href="#">here</a> to close this window.

<script type="text/javascript">

    function CloseWindow() {
         open(location, '_parent').close()
    }
</script>

正在重定向到在线申请页面。

我将如何关闭选项卡本身。

self.close(); 适用于 IE,Chrome 但在 Mozilla 中显示错误:

Scripts may not close windows that were not opened by script.

或者我们可以让“dom.allow_scripts_to_close_windows, true;'使用 c# 或 javascript?

你为什么用那种方式?只需使用:

function CloseWindow() {
  window.parent.close();
}

或者,您可以使用:

function CloseWindow() {
  window.close();
}

如果您在 HTML 中使用脚本,请使用如下标签包装它:

Please click <a  onclick="CloseWindow();" href="#">here</a> to close this window.
<script type="text/javascript">
   function CloseWindow() {
      window.parent.close();
   }
</script>