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

Javascript eliminates window.close() prompt window_javascript tips

WBOY
Release: 2016-05-16 15:58:17
Original
1263 people have browsed it

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>
 
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template