console
window.addEventListener("load",function(){
var oOpenBaiduBtn=this.document.getElementById("openBaiduBtn");
var oBaiduWin=null;
oOpenBaiduBtn.addEventListener("click",function(){
oBaiduWin=window.open("http://www.baidu.com","_blank");
});
var oCloseBaiduBtn=this.document.getElementById("closeBaiduBtn");
oCloseBaiduBtn.addEventListener("click",function(){
oBaiduWin.close();
});
var oOpenNewBtn=this.document.getElementById("openNewBtn");
var oNewWin=null;
oOpenNewBtn.addEventListener("click",function(){
oNewWin=window.open();
})
var oChangeNewBtn=this.document.getElementById("changeNewBtn");
oChangeNewBtn.addEventListener("click",function(){
oNewWin.document.title="新窗口";
oNewWin.document.body.innerHTML="<div><p><strong>Hi</strong>,I'm a new window</p></div>";
oNewWin.document.body.style.color="blue";
})
var oCloseNewBtn=this.document.getElementById("closeNewBtn");
oCloseNewBtn.addEventListener("click",function(){
oNewWin.close();
})
});
var oAlertBtn = this.document.getElementById("alertBtn");
oAlertBtn.addEventListener("click",function()
{
window.alert("我是告警窗口");
});
var oConfirmBtn = this.document.getElementById("confirmBtn");
oConfirmBtn.addEventListener("click",function()
{
var bConfirmed = window.confirm("你要不要打开百度?");
if(bConfirmed)
{
window.open("https://www.baidu.com/?tn=15007414_8_dg");
}
});
var oPromptBtn = this.document.getElementById("promptBtn");
oPromptBtn.addEventListener("click",function()
{
var strText=window.prompt("请输入提示:");
if(strText){
var oText=window.document.getElementById("text");
oText.innerHTML=strText;
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
</script>
</head>
<body>
<div>
<button id="openBaiduBtn">打开百度</button>
<button id="closeBaiduBtn">关闭百度</button>
</div>
<br/>
<div>
<button id="openNewBtn">打开空白页面</button>
<button id="changeNewBtn">绘制空白页面</button>
<button id="closeNewBtn">关闭空白页面</button>
</div>
<br/>
<div>
<button id="alertBtn">打开告警窗口</button>
<button id="confirmBtn">打开确认窗口</button>
<br/>
<div>
<button id="promptBtn">打开提示窗口</button>
<label>提示文字:</label><p id="text"></p>
</div>
</div>
</body>
</html>