how to close a parent window?

时光毁灭记忆、已成空白 提交于 2019-12-13 03:02:33

问题


I have a application form when I submit the form it is redirecting to window which have options "print" and close.

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

If I click on close,the tab itself closing in chrome and IE but it not working in Mozilla.

When I use this code,

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

<script type="text/javascript">

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

it is redirecting to apply online page.

How I will close the tab itself.

self.close(); is working for IE and Chrome but in Mozilla it shows the error:

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

Or can we make ' dom.allow_scripts_to_close_windows, true;' using c# or javascript?


回答1:


Why are you using that way? Just use:

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

Or, you can use:

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



回答2:


If you are using script in HTML wrap it with tag like:

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


来源:https://stackoverflow.com/questions/32182928/how-to-close-a-parent-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!