JavaScript中window.open()打开与window.close()关闭
close()关闭窗口,语法书写如下,其次使用close()在打开新窗口的同时,关闭该窗口,是看不到被打开窗口的
1 window.close();//关闭本窗口 2 <窗口对象>.close();//关闭指定的窗口
代码展示:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript中window.open()与window.close()</title>
<script type="text/javascript">
function myopen(){
window.open(‘https://www.baidu.com/‘,‘_blank‘,‘width=300,height=200,left=0,meunbar=no,toolbar=no,scrollbar=yes,status=no‘);
}
var ceshi=window.open(‘https://www.cnblogs.com/dhnblog/p/12494648.html‘)//将新打的窗口对象,存储在变量ceshi中
// // ceshi.wondows.close() 错误写法
ceshi.close()
</script>
</head>
<body>
<input type="button" name="" id="" value="点击打开新窗口" onclick="myopen()" />
</body>
</html>使用<窗口对象>.close();//关闭指定的窗口 代码展示:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>通过变量关闭窗口</title>
<script type="text/javascript">
function myopen(){
var ceshi=window.open(‘https://www.baidu.com/‘,‘_blank‘,‘width=300,height=200,left=0,meunbar=no,toolbar=no,scrollbar=yes,status=no‘);
ceshi.close()
}
</script>
</head>
<body>
<input type="button" name="" id="" value="我不信你可以打开" onclick="myopen()" />
</body>
</html>至于window.close();//关闭本窗口 暂时不是很懂,感兴趣的可以参考下这个,后期有机会在完善