在彈出的窗口中加入關(guān)閉按鈕,點(diǎn)擊后彈出的窗口關(guān)閉。
本實(shí)例主要應(yīng)用 window 對(duì)象的 close()方法實(shí)現(xiàn)。close()方法的語法如下。
window.close()
功能:window 對(duì)象的 close()方法用于自動(dòng)關(guān)閉瀏覽器窗口。
實(shí)現(xiàn)過程
1.要彈出的窗口且是功能實(shí)現(xiàn)界面 New.html。
<html>
<head>
<meta charset="utf-8" />
<title>彈出的窗口</title>
<style type="text/css">
body{
background-image:url(new.jpg);
background-repeat:no-repeat;
}
</style>
</head>
<body>
<input type = "button" value = "關(guān)閉" onClick="window.close();"/>
</body>
</html>
2.在 index.html 頁面寫上 JS 代碼實(shí)現(xiàn)功能
<html>
<head>
<meta charset="utf-8" />
<script type="text/jscript" language="javascript">
window.open("new.html","new","height=280,width=800,top=10,left=20,resizable=no, location=no",false);
</script>
<style type="text/css">
p{
font-size:24px;
color:#F00;
}
</style>
</head>
<body>
<p>網(wǎng)站首頁</p>
</body>
</html>