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

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

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

1
<inputtype="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>
<inputid="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>
<metacharset="utf-8">
<title>html中</title>
</head>
<bodyonbeforeunload="return myFunction()">
<p>该实例演示了如何向 body 元素添加 "onbeforeunload" 事件。</p>
<p>关闭当前窗口,点击以下链接触发 onbeforeunload 事件。</p>
<ahref="http://www.gree020.cn">点击跳转到远方资源</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>
<metacharset="utf-8">
<title>JavaScript 中</title>
</head>
<body>
    <p>该实例演示了如何使用 HTML DOM 向 body 元素添加 "onbeforeunload" 事件。</p>
    <p>关闭当前窗口,按下 F5 或点击以下链接触发 onbeforeunload 事件。</p>
    <ahref="http://www.gree020.cn">点击调转到远方资源</a>
<script>
    window.onbeforeunload = function(event) {
        event.returnValue = "我在这写点东西...";
    };
</script>
</body>
</html>

到此这篇关于HTML页面点击按钮关闭页面的多种方式的文章就介绍到这了希望大家以后多多支持远方资源!

简简单单挺好的

联系我们 订单查询