為什么網(wǎng)頁(yè)打不開(kāi)?
<!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 window=confirm("新窗口打開(kāi)網(wǎng)站");
? ? ? if(window==true){
? ? ? ? ? var http = prompt("請(qǐng)輸入網(wǎng)站地址","http://idcbgp.cn");?
? ? ? ? ? if(http!=null){
? ? ? ? ? ? ? window.open(url,"_blank","width=400px,height=500px,menubar=no,tolbar=no");
? ? ? ? ? }else{
? ? ? ? ? alert("88");
? ? ? ? ? }
? ? ? }else{
? ? ? ? ? alert("88");
? ? ? }
? ? ??
? ? ? }
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開(kāi)網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2016-01-25
window.open("http://www.baidu.com"...)要是完整url,變量不要用window,可以用window1,還有注意符號(hào)。
2016-01-25
樓上說(shuō)的很對(duì)。
1.把window = confirm(...); 改為其他,入res
2.改window.open(http,"_blank","width=400px,height=500px,menubar=no,tolbar=no");
另外判斷還可以精簡(jiǎn)為if(res)和if(http)
2016-01-25
你的URL沒(méi)寫(xiě);?
window關(guān)鍵字不能當(dāng)成 變量名
正確寫(xiě)法:
function openWindow(){
? ? ? var str=confirm("新窗口打開(kāi)網(wǎng)站");
? ? ? if(str==true){
? ? ? ? ? var http = prompt("請(qǐng)輸入網(wǎng)站地址","http://idcbgp.cn");?
? ? ? ? ? if(http!=null){
? ? ? ? ? ? ? window.open("http://idcbgp.cn","_blank","width=400px,height=500px,menubar=no,tolbar=no");
? ? ? ? ? }else{
? ? ? ? ? alert("88");
? ? ? ? ? }
? ? ? }else{
? ? ? ? ? alert("88");
? ? ? }
? ? ??
? ? ? }