HTML页面点击按钮关闭页面的几种方式
文章目录
- HTML页面点击按钮关闭页面的几种方式
- 一、不带任何方式的关闭窗口
- 二、提示之后关闭页面
- 三、点击关闭本页面并跳转到其他页面
- 四、将 三 中的方法放到js中
一、不带任何方式的关闭窗口
<input type="button" name="close" value="关闭" onclick="window.close();" />
二、提示之后关闭页面
<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()" />
三、点击关闭本页面并跳转到其他页面
<!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.runoob">点击跳转到菜鸟教程</a>
<script>
function myFunction() {
return "我在这写点东西...";
}
</script>
</body>
</html>
四、将 三 中的方法放到js中
<!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">点击调转到菜鸟教程</a>
<script>
window.onbeforeunload = function(event) {
event.returnValue = "我在这写点东西...";
};
</script>
</body>
</html>
更多推荐
HTML_页面点击按钮关闭页面的几种方式
发布评论