qq_慕田峪7133820
2022-01-26 10:20
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
<script type="text/javascript">
var mywin=window.open("http://www.imooc.com");
function close(){
var answer=confirm("是否要关闭此窗口?");
if(answer==true){
mywin.close();
alert("已关闭");
}else
{
alert("关闭失败");
}
}
</script>
</head>
<body>
<input type="submit" value="点击关闭" onclick="close()"/>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
<script type="text/javascript">
function Wopen() {
var answer = confirm("是否要打开此窗口?");
var main = window.open('http://www.imooc.com','_blank');
if (answer == true) {
main.close();
window.close();
} else {
alert("打开失败");
}
}
</script>
</head>
<body>
<input name="button" type="button" onClick=" Wopen()" value="点击我,打开新窗口!" />
</body>
</html>
这样就好了
我也是个web初学者,但是有编程经验,我觉得应该是close是一个内置的方法
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
<script type="text/javascript">
var mywin=window.open("http://www.imooc.com");
function closeWindow(){
var answer=confirm("是否要关闭此窗口?");
if(answer==true){
mywin.close();
alert("已关闭");
}else
{
alert("关闭失败");
}
}
</script>
</head>
<body>
<input type="submit" value="点击关闭" onclick="closeWindow()"/>
</body>
</html>
上面这样是可以的,把close函数名换成别的就好了
JavaScript入门篇
739817 学习 · 9566 问题
相似问题