我是靠谱客的博主 勤奋手链,这篇文章主要介绍html如何关闭当前页面,现在分享给大家,希望可以做个参考。

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

html关闭当前页面的方法:

1、自定义提示关闭

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
<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、在即将离开当前页面(刷新或关闭)时

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

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!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>
登录后复制
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!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如何关闭当前页面内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(602)

评论列表共有 0 条评论

立即
投稿
返回
顶部