<script type="text/javascript"> function openWindow(){ // 新窗口打开时弹出确认框,是否打开 var a=confirm("是否打开输入对话框"); // 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/ if(a==true){ var b=prompt("请输入你要打开的网址:","http://www.imooc.com/") if(b!=null){ window.open('b','width=400','height=500','menubar=no','toolbar=no') } else{ window.open('http://www.imooc.com','height=500','menubar=no','toolbar=no') } } } //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏。 </script>
为何我如上的代码,打开imooc网站显示的却是"http://www.imooc.com/error/noexists"错误页面而不是慕课网正常的首页
window.open('b','width=400','height=500','menubar=no','toolbar=no')改为
window.open(b,'width=400','height=500','menubar=no','toolbar=no')
==true这里一个=就可以了吧
if(a==true)中的true删掉, 不然会导致取消功能失效。
应该为:if(a)这样就可以。
if(b!=null){
window.open('b','width=400','height=500','menubar=no','toolbar=no')
}
else{
window.open('http://www.imooc.com','height=500','menubar=no','toolbar=no')
}
这里的判定也删掉, 直接在后面
写上:
if(a==true){
var b=prompt("请输入你要打开的网址:","http://www.imooc.com/");
window.open(b,'_blank','width=400,height=500,menubar=no,toolbar=no');