<!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 message=prompt("请输入对应网址", "");
if (message==false)
{ alert("wrong address");
}
else
{ rec(); }
}
function rec()
{
var a=confirm("是否打开网页?");
if (a==true)
{ window.open('message','_blank','width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes'); }
else { alert("您已取消进入")}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
<!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 message=prompt("请输入对应网址", "");
if (message==false)
{ alert("wrong address");
}
else
{ rec(message); }
}
function rec(net)
{
var a=confirm("是否打开网页?");
if (a==true)
{ window.open(net,'_blank','width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes'); }
else { alert("您已取消进入")}
}
</script>
</head>
<body>
<input type="button" value="新窗口打开网站" onclick="openWindow()" />
</body>
</html>
message没有传过去。window.open 这里的message,你使用了单引号,代表的是一个字符串了。要用变量,就要去掉引号。可以改成
else{
rec(message);
}
window.open(message,'_blank','width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes');
var message=prompt("请输入对应网址", "");
message会被赋值为输入的网址,例如你输入的是“http://www.imooc.com/”;
message放在window.open里如下所示:
window.open(message,"_blank","width=600,height=400,menubar=no,toolbar=no, status=no,scrollbars=yes");