代碼寫的應該沒有問題,為什么點擊了右面的按鈕沒有反應?
<!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 str1=confirm("是否打開新窗口!");
? ? if(str1==true){
? ? ? var str=prompt("請輸入url:","http://www.xianlaiwan.cn/");
? ? ? ?if(url!=null){
? ? ? ?window.open(str,'_blank',width=400px,height=500px,menubar=no,toolbar=no);
? ? ? ?}
? ? ? ?else{
? ? ? ? ? ?document.write("url為空!");
? ? ? ?}
? ? }
? }
? </script>?
?</head>?
?<body>?
? ? ? <input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
2016-02-17
啊,我知道你代碼的問題了
1、if(url!=改為if(str!=
2、window.open(str,'_blank',width=400px,height=500px,menubar=no,toolbar=no);改為window.open(str,'_blank','width=400px,height=500px,menubar=no,toolbar=no');即參數需要用單引號或雙引號括起來;
3、還是11行?if(url!=null){改為?if(str!=null){后依然有些問題,需要改為?if(url){或?if(url!=""){,否則第二個對話框點取消時會打開一個空窗口
2016-02-17
試了你的代碼,改url為str后,執行正常,我估計是你瀏覽器的問題,換個瀏覽器試試。
2016-02-16
樓上正解
2016-02-16
if(url!=null) 改為 if(str!=null)