求助大神,為什么我這個(gè)按鈕不能關(guān)閉網(wǎng)頁(yè) 是哪里錯(cuò)了,求指點(diǎn)!
??
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="UTF-8">
? ? <title>自制網(wǎng)頁(yè)打開</title>
</head>
<body>
? ? <script type="text/javascript"> ?
? ?function openWindow()
? ? ? ? {var open=confirm("是否打開?");
? ? ? ? if(open=true)
? ? ? ? ? {var url=prompt("輸入網(wǎng)址","http://idcbgp.cn/");
? ? ? ? ? ? ? ? ?if(url != null)
? ? ? ? ? ? ? ? ? ? ?{window.open(url,'_blank','width=400px,height=500px,menubar=no,toolbar=no');//_blank重新打開一個(gè)網(wǎng)頁(yè)。_self再此頁(yè)面打開一個(gè)網(wǎng)頁(yè), _top:框架網(wǎng)頁(yè)中在上部窗口中顯示目標(biāo)網(wǎng)頁(yè)
? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ?{alert("baibai!");}
? ? ? ? ? }
? ? ? ? ?else
? ? ? ? ?{alert("再見!");}
? ? ? ?
? ? ? // url.close();window.close(); ? //關(guān)閉本窗口
//<窗口對(duì)象>.close(); ? //關(guān)閉指定的窗口?
? ? }
? ? function guanbi(){
? ? ? var a="http://idcbgp.cn/";
? ? ? a.close();
? ? } ?
? ??
? </script>?
? ?<input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
? ?<input type="button" value="關(guān)閉新窗口打開網(wǎng)站" onclick="guanbi()" />?
?
?
</body>
</html>
2018-05-27
我想樓主是想實(shí)現(xiàn)這種功能吧,那就需要把新打開的窗口對(duì)象存儲(chǔ)在全局變量里,這樣才可以在guanbi()函數(shù)里調(diào)用close(),關(guān)閉剛剛打開的窗口
關(guān)于js的全局變量,樓主可以參考 JS中聲明全局變量
2018-07-30
if(open==true)
2018-06-17
我也是關(guān)閉按鈕不起作用。求解
2018-05-22
同樓上,我也是可以關(guān)閉的
2018-05-22
我直接拷貝你的代碼運(yùn)行是可以關(guān)閉的哦 ? ?瀏覽器問題吧 ?