网页有些时候不需要等待用户的操作而自动关闭。例如子窗口的作用已经结束,或者本窗口已经过期需要关闭,可以使用JavaScript实现这个效果。
补充下面代码,要求用户点击【关闭此窗口】按钮后,页面进行关闭。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>JS网页特效实例:动态关闭页面</title>
<script>
function closeWindow() {
// 补充代码
}
</script>
</head>
<body style="text-align:center;">
<p>
<input type="button" value="关闭页面" onclick="closeWindow()" />
</p>
</body>
</html>
相关知识点:
window.close()
参考代码:
function closeWindow() {
window.close();
}