js關閉當前彈出的小視窗並開啟新視窗
阿新 • • 發佈:2019-01-06
一、頁面執行流程說明:
1.點選父頁面a.html的“點我開啟新視窗”按鈕-->彈出新視窗(b.html)
2.點選b.html的超連結“關閉當前視窗並開啟新頁面”-->關閉當前視窗b.html,並開啟新頁面c.html
二、實現步驟:
要點:1.給按鈕的點選事件編寫函式f1(),用於彈出新視窗 window.open(新視窗的url,"",視窗引數)
2.給彈出的新視窗b.html的超連結“關閉當前視窗並開啟新頁面”新增點選事件f2(),用來關閉當前視窗並開啟新頁面
三、程式碼:
1.父頁面 a.html <head> <script> function f1(){ window.open("b.html","","width=800px,height=600px"); } </script> </head> <body> <button onclick="f1()">點我開啟新視窗</button> </body>
2.子頁面 b.html
<head>
<script>
function f2() {
window.close();
window.open("c.html");
}
</script>
</head>
<body>
<a href="javascript:void(0);" onclick="f2()">點我關閉當前視窗並開啟新視窗</a>
</body>
3.b.html關閉後開啟的新頁面 c.html
<body>
<h2>這是c.html</h2>
</body>