console
window.addEventListener("load",function(){
var oBaiduWin;
var oOpenBaiduBtn=this.document.getElementById("openBaiduBtn");
oOpenBaiduBtn.addEventListener("click",function(){
oBaiduWin=window.open("http://www.baidu.com","_blank");
},false);
var oCloseBaiduBtn=this.document.getElementById("closeBaiduBtn");
oCloseBaiduBtn.addEventListener("click",function(){
oBaiduWin.close();
},false);
var oBlankWin;
var oOpenNewBtn=this.document.getElementById("openNewBtn");
oOpenNewBtn.addEventListener("click",function(){
oBlankWin=window.open();
});
var oChangeNewBtn=this.document.getElementById("changeNewBtn");
oChangeNewBtn.addEventListener("click",function(){
oBlankWin.document.title="新窗口";
oBlankWin.document.body.style.color="blue";
console.log(oBlankWin.location.href);
oBlankWin.document.URL="http://www.baidu.com";
console.log(oBlankWin.location.href);
});
var oCloseNewBtn=this.document.getElementById("closeNewBtn");
oCloseNewBtn.addEventListener("click",function(){
oBlankWin.close();
},false);
var oAlertBtn=this.document.getElementById("alertBtn");
oAlertBtn.addEventListener("click",function(){
window.alert("我是告警窗口");
},false);
var oConfirmBtn=this.document.getElementById("confirmBtn");
oConfirmBtn.addEventListener("click",function(){
var bOpen=window.confirm("你想打开百度吗?");
if(bOpen){
window.open("http://www.baidu.com","_blank");
}
},false);
var oPrompTBtn=this.document.getElementById("promptBtn");
oPrompTBtn.addEventListener("click",function(){
var oText=window.document.getElementById("text");
var text=window.prompt("请输入提示文字:");
oText.innerHTML=text;
},false);
var ostarttimebtn=this.document.getElementById("starttimer");
var ostoptimebtn=this.document.getElementById("stoptimer");
var otimerbox=this.document.getElementById("timerBox");
var timer;
function changecolor(){
otimerbox.style.backgroundColor="red";
}
ostarttimebtn.addEventListener("click",function(){
timer=window.setTimeout(changecolor,2000)
});
ostoptimebtn.addEventListener("click",function(){
window.clearTimeout(timer);
});
var ostartintervalbtn=this.document.getElementById("startinterval");
var ostopintervalbtn=this.document.getElementById("stopinterval");
var ointervalbox=this.document.getElementById("intervalBox");
var ointervaltext=this.document.getElementById("intervalText");
var interval;
var count=6;
ointervaltext.innerHTML=count;
function changecolorinterval(){
var colors=["hotpink","blue","green","yellow","red","lightskyblue",];
if(count>0){
--count;
var color=colors[count];
ointervalbox.style.backgroundColor=color;
ointervaltext.innerHTML=count;
}
}
ostartintervalbtn.addEventListener("click",function(){
window.clearInterval(interval);
count=6;
ointervaltext.innerHTML=count;
interval=window.setInterval(changecolorinterval,2000)
});
ostopintervalbtn.addEventListener("click",function(){
window.clearInterval(interval);
});
console.log(window.location.href);
console.log(window.location.search);
console.log(window.location.hash);
console.log(window.navigator.userAgent);
console.log(document.URL);
},false)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
</style>
<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>
<button id="alertBtn"">打开告警窗口</button>
<button id="confirmBtn"">打开确认窗口</button>
<button id="promptBtn"">打开提示窗口</button>
</br>
</br>
<div>
<label>提示文字:</label><p id="text" ></p>
</div>
<br/>
<div>
<button id = "starttimer">开始</button>
<button id = "stoptimer">结束</button>
<div id="timerBox"></div>
</div>
<br/>
<div>
<button id = "startinterval">开始</button>
<button id = "stopinterval">结束</button>
<div id="intervalBox"></div>
<span>倒计时:</span><span id="intervalText"></span>
</div>
</body>
</html>
#timerBox {
width: 100px;
height: 100px;
border : 1px solid black;
background-color: lightblue;
}
#intervalBox {
width: 100px;
height: 100px;
border : 1px solid black;
background-color:royalblue;
}