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='button_colse.html' 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('','_self');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!