Home > Article > Web Front-end > How to close the current page in html
html Methods to close the current page: 1. Customize the prompt to close; 2. When the user is about to leave the current page, the user clicks the close button onbeforeunload event in the browser's maximize-minimize close button.
The operating environment of this tutorial: windows7 system, html5 version, DELL G3 computer.
htmlMethods to close the current page:
1. Customize the prompt to close
<script language="javascript"> // 这个脚本是 ie6和ie7 通用的脚本 function custom_close(){ if(confirm("您确定要关闭本页吗?")){ window.opener=null; window.open('','_self'); window.close(); } else{ } } </script> <input id="btnClose" type="button" value="关闭本页" onClick="custom_close()" />
2. When you are about to leave the current page (refresh or close) When
The user clicks the close button in the maximize or minimize close button of the browser
The onbeforeunload event is triggered when the current page is about to be left (refreshed or closed).
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>html中</title> </head> <body onbeforeunload="return myFunction()"> <p>该实例演示了如何向 body 元素添加 "onbeforeunload" 事件。</p> <p>关闭当前窗口,按下 F5 或点击以下链接触发 onbeforeunload 事件。</p> <a href="http://www.runoob.com">点击调整到菜鸟教程</a> <script> function myFunction() { return "我在这写点东西..."; } </script> </body> </html>rrree
Related learning recommendations: html video tutorial
The above is the detailed content of How to close the current page in html. For more information, please follow other related articles on the PHP Chinese website!