<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
function openWindow()
{
var ask = confirm("是否打开新的窗口?");
if(ask==true){
var open = prompt("请输入要打开的网址","http://www.baidu.com/");
else{
alert("(●'◡'●)傲娇!");
}
if(open!=null){
window.open(open,'_blank','width=400px,height=500px,menubar=no,toolbar=no');
}
else{
alert("(•ω•`)o拜拜!");
}
}
else{
alert("(•ω•`)o那就不打开喽!");
}
}
</script>
</head>
<body>
<input type="button" value="新窗口点我" onclick="openWindow()" />
<input type="button" value="关窗口点我" onclick="closeWindow()"/>
</body>
</html>
自己琢磨close()了好多次琢磨不出来这个功能,求解答一下
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
var mywin="";
var tag=0;
function closeWindow()
{
if(tag==1)
{
mywin.close();
tag=0;
}
}
function openWindow()
{
var ask = confirm("是否打开新的窗口?");
if(ask==true){
var open = prompt("请输入要打开的网址","http://www.baidu.com/");
if(open!=null){
tag=1;
mywin= window.open(open,'_blank','width=400px,height=500px,menubar=no,toolbar=no');
}
else{
alert("(•ω•`)o拜拜!");
}
}
else{
alert("(•ω•`)o那就不打开喽!");
}
}
</script>
</head>
<body>
<input type="button" value="新窗口点我" onclick="openWindow()" />
<input type="button" value="关窗口点我" onclick="closeWindow()"/>
</body>
</html>