HTML页面点击按钮关闭页面的几种方式
一、不带任何方式的关闭窗口
<inputtype="button"name="close"value="关闭"onclick="window.close();"/>
二、提示之后关闭页面
<script>
functioncustom_close(){
if(confirm("您确定要关闭本页吗?")){
window.opener=null;
window.open('','_self');
window.close();
}
else{
}
}
</script>
<inputid="btnClose"type="button"value="关闭本页"onClick="custom_close()"/>
三、点击关闭本页面并跳转到其他页面
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<title>html中</title>
</head>
<bodyonbeforeunload="returnmyFunction()">
<p>该实例演示了如何向body元素添加"onbeforeunload"事件。</p>
<p>关闭当前窗口,点击以下链接触发onbeforeunload事件。</p>
<ahref="http://www.yc58.com">点击跳转到壹家怡园</a>
<script>
functionmyFunction(){
return"我在这写点东西...";
}
</script>
</body>
</html>
四、将三中的方法放到js中
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<title>JavaScript中</title>
</head>
<body>
<p>该实例演示了如何使用HTMLDOM向body元素添加"onbeforeunload"事件。</p>
<p>关闭当前窗口,按下F5或点击以下链接触发onbeforeunload事件。</p>
<ahref="http://www.yc58.com">点击调转到壹家怡园</a>
<script>
window.onbeforeunload=function(event){
event.returnValue="我在这写点东西...";
};
</script>
</body>
</html>
|