html如何关闭当前页面

ID:9612 / 打印
html关闭当前页面的方法:1、自定义提示关闭;2、在即将离开当前页面时,用户点浏览器的最大化最小化关闭按钮中的关闭按钮onbeforeunload事件。

html如何关闭当前页面

本教程操作环境:windows7系统、html5版,DELL G3电脑。

html关闭当前页面的方法:

1、自定义提示关闭

<script language="javascript"> // 这个脚本是 ie6和ie7 通用的脚本 function custom_close(){     if(confirm("您确定要关闭本页吗?")){         window.opener=null;         window.open(&#39;&#39;,&#39;_self&#39;);         window.close();     }     else{     } } </script> <input id="btnClose" type="button" value="关闭本页" onClick="custom_close()" />

2、在即将离开当前页面(刷新或关闭)时

立即学习“前端免费学习笔记(深入)”;

用户点浏览器的最大化最小化关闭按钮中的关闭按钮时

onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发。

<!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>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript 中</title> </head> <body>     <p>该实例演示了如何使用 HTML DOM 向 body 元素添加 "onbeforeunload" 事件。</p>     <p>关闭当前窗口,按下 F5 或点击以下链接触发 onbeforeunload 事件。</p>     <a href="http://www.runoob.com">点击调整到菜鸟教程</a> <script>     window.onbeforeunload = function(event) {         event.returnValue = "我在这写点东西...";     }; </script> </body> </html>

相关学习推荐:html视频教程

上一篇: html如何设置溢出隐藏
下一篇: html图片怎么插入

作者:admin @ 24资源网   2024-09-27

本站所有软件、源码、文章均有网友提供,如有侵权联系308410122@qq.com

与本文相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。