close()
Window close() 方法
定义和用法
close() 方法用于关闭浏览器窗口。
语法
window.close()
浏览器支持
所有主要浏览器都支持 close() 方法
实例
下面的例子可关闭新的浏览器:
<html>
<head>
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>This is ‘myWindow‘</p>");
}
function closeWin()
{
myWindow.close();
}
</script>
</head>
<body>
<input type="button" value="Open ‘myWindow‘" onclick="openWin()">
<input type="button" value="Close ‘myWindow‘" onclick="closeWin()">
</body>
</html>
<head>
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>This is ‘myWindow‘</p>");
}
function closeWin()
{
myWindow.close();
}
</script>
</head>
<body>
<input type="button" value="Open ‘myWindow‘" onclick="openWin()">
<input type="button" value="Close ‘myWindow‘" onclick="closeWin()">
</body>
</html>