Home  >  Article  >  Web Front-end  >  Implement a method to close the window by clicking on a newly opened page

Implement a method to close the window by clicking on a newly opened page

一个新手
一个新手Original
2017-10-24 09:13:551747browse

1. During the development process, our front-end user experience sometimes requires clicking a button to close the current browser window. You can do it with html DOM.

2. Note: This writing method requires closing in a new window. target="_blank"

3. Open b.html from a.html and click the button in page b to close page B

4. Code of a page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 </head>
 <body>
  <div>
  <a href=&#39;button_colse.html&#39; target="_blank">测试点击按钮关闭当前页面</a>
  </div>
 </body>
</html>

5 . bPage code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css"></style>
  <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
 </head>
 <body>
  <div>
  点击我关闭本页面
  </div>
  <button  onclick="javascript:window.opener=null;window.open(&#39;&#39;,&#39;_self&#39;);window.close();" type="button" role="button" aria-disabled="false">
        <span class="ui-button-text">
        <span>关闭</span>
        </span>
 </button>
 </body>
</html>

The above is the detailed content of Implement a method to close the window by clicking on a newly opened page. For more information, please follow other related articles on the PHP Chinese website!

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