Home  >  Article  >  Web Front-end  >  Javascript eliminates window.close() prompt window_javascript tips

Javascript eliminates window.close() prompt window_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:58:171189browse

The script Window.close() is used to close the current window. If Window.close() is executed in the window of window.open, the window will be closed smoothly, but if it is executed in a non-window Execute Window.close() in the window opened by .open, a prompt window will pop up, as follows:

It is also very simple to eliminate this prompt box in the program, but it is slightly different in IE6 and IE7

1. IE6

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>IE6Close</title>
  <script type="text/javascript">
  function closeWin()
  {
    window.opener=null;
    window.close();
  }
  </script>
</head>
<body>
  <form id="form2" runat="server">
  <div>
    <input id="btnClose" type="button" value="close" onclick="closeWin()"/>
  </div>
  </form>
</body>
</html>
 

2.IE7

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>IE7Colse</title>
  <script type="text/javascript">
  function closeWin()
  {
    window.open('','_self','');
    window.close();
  }
  </script>
</head>
<body>
  <form id="form2" runat="server">
  <div>
    <input id="btnClose" type="button" value="close" onclick="closeWin()"/>
  </div>
  </form>
</body>
</html>

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn