我的代碼里的 關(guān)閉新打開(kāi)窗口 怎么實(shí)現(xiàn)?
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>? ?
? <script type="text/javascript"> ?
??? function openWindow(){
?? ??? ?// 新窗口打開(kāi)時(shí)彈出確認(rèn)框,是否打開(kāi)
?? ??? ?var newWin = confirm("你要打開(kāi)新的網(wǎng)頁(yè)窗口嗎?");
?? ??? ?if(newWin == true){
?? ??? ???? op();
?? ??? ?}else{
?? ??? ??? ?alert("好的再見(jiàn)!");
?? ??? ?};?? ?
?? ?}
?? ?
??? function op(){
????? // 通過(guò)輸入對(duì)話框,確定打開(kāi)的網(wǎng)址,默認(rèn)為 http://idcbgp.cn/
?? ??? ??? ?var purl = "http://idcbgp.cn";
?? ??? ??? ?var input = prompt("請(qǐng)輸入網(wǎng)址打開(kāi)新窗口",purl);
?? ??? ??? ?var x=0;
?? ??? ??? ?var y=0;
?? ??? ??? ?if(input != null){//打開(kāi)的窗口要求,寬400像素,高500像素,無(wú)菜單欄、無(wú)工具欄
?? ??? ??? ??? ??? ?var win = open(purl,"_blank","top=y,left=x,width=400,height=500,menubar=no,toolbar=no");
?? ??? ??? ?};
??? }
?? ?
?? ?function closeWin(){
?? ??? ?win.close();
?? ?}
? </script>
?</head>
?<body>
?<form>
?? ?? <input type="button" value="請(qǐng)單擊我打開(kāi)新的窗口!" onclick="openWindow()" />
??? <input type="button" value="關(guān)閉新打開(kāi)的窗口" onclick="closeWin()" />
</form>
?</body>
</html>
2015-09-29
語(yǔ)法是 <窗口對(duì)象>.close() ,因此,你要在function外先聲明窗口變量。以下是我的代碼,看關(guān)鍵的兩行即可。
2015-09-28