系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 网页制作 > HTML/Xhtml > 详细页面

HTML页面点击按钮关闭页面的多种方式

时间:2022-12-06来源:www.pcxitongcheng.com作者:电脑系统城

这篇文章给大家分享HTML页面点击按钮关闭页面的几种方式,实现思路非常简单,有不带任何方式的关闭窗口,提示之后关闭页面,点击关闭本页面并跳转到其他页面等等,每种方式结合实例代码给大家介绍的非常详细,需要的朋友参考下吧

HTML页面点击按钮关闭页面的几种方式

一、不带任何方式的关闭窗口

1 <input type="button" name="close" value="关闭" onclick="window.close();" />

二、提示之后关闭页面

1
2
3
4
5
6
7
8
9
10
11
12
<script>
function custom_close(){
    if(confirm("您确定要关闭本页吗?")){
        window.opener=null;
        window.open('','_self');
        window.close();
    }
    else{
    }
}
</script>
<input id="btnClose" type="button" value="关闭本页" onClick="custom_close()" />

三、点击关闭本页面并跳转到其他页面

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>关闭当前窗口,点击以下链接触发 onbeforeunload 事件。</p>
<a href="http://www.jb51.net">点击跳转到脚本之家</a>    
<script>
    function myFunction() {
        return "我在这写点东西...";
    }
</script>
</body>
</html>

四、将 三 中的方法放到js中

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.jb51.net">点击调转到脚本之家</a>
<script>
    window.onbeforeunload = function(event) {
        event.returnValue = "我在这写点东西...";
    };
</script>
</body>
</html>

到此这篇关于HTML页面点击按钮关闭页面的多种方式的文章就介绍到这了

分享到:

相关信息

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载