<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>编程练习</title> <script type = "text/Javascript"> //新窗口打开前弹出确认框,是否打开 function Openwindow(){ var ifOpen = confirm(是否打开窗口?); if(ifOpen == true){ var url = prompt("请输入你要打开的网址","http://www.imooc.com")"; window.open('url','_blank', 'width = 400px,height = 500px,menubar :no,toolbar:no'); } } </script> </head> <body> <input name = "button" type = "button" value = "新窗口打开网站" onClick= "Openwindow()"> </body> </html>
执行完,点击“新窗口打开网页”没反应呢?
修改代码如下:有两处有问题。1:第九行,内容加引号。2.第11行,最后面多了个引号。粗心大意了。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>编程练习</title>
<script type = "text/Javascript">
//新窗口打开前弹出确认框,是否打开
var Openwindow = function (){
var ifOpen = confirm('是否打开窗口?');
if(ifOpen == true){
var url = prompt("请输入你要打开的网址","http://www.imooc.com");
window.open('url','_blank',
'width = 400px,height = 500px,menubar :no,toolbar:no');
}
}
</script>
</head>
<body>
<input name="button" type="button" value="新窗口打开网站" onclick="Openwindow()">
</body>
</html>