SOURCE

console 命令行工具 X clear

                    
>
console
//是load不是onload
window.addEventListener("load",function(){
    var oBaiduWin;
//打开百度 此时的this是当前的窗口
    var oOpenBaiduBtn=this.document.getElementById("openBaiduBtn");
    oOpenBaiduBtn.addEventListener("click",function(){
        //这个函数被openBaiduBtn调用,此时的this就是这个button
        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.innerHTML="<div><strong>Hi!!</strong></div>";
        console.log(oBlankWin.location.href);
        //可以跳转到该网页的位置
        //oBlankWin.location.href="http://www.baidu.com";
        //只是用来查看网址,并不能跳转到百度网页
        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");
        } 
    },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 oStartTimerBtn=this.document.getElementById("startTimer");
    var oStopTimerBtn=this.document.getElementById("stopTimer");
    var oTimerBoxBtn=this.document.getElementById("timerBox");
    var timer;

    function changeColor(){
        oTimerBoxBtn.style.backgroundColor="red";   
    }
    oStartTimerBtn.addEventListener("click",function(){
        timer=window.setTimeout(changeColor,2000)
    });
    oStopTimerBtn.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;

    function changeColorInterval(){
        var colors=["hotpink","blue","green","yellow","lightskyblue","red"];
        if(count>0){
            --count;
            var color=colors[count];
            oIntervalBox.style.backgroundColor=color; 
            oIntervalText.innerHTML=count;
        }
    }
    oStartIntervalBtn.addEventListener("click",function(){
        window.clearInterval(interval);
        count=6;
        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);

    if(window.navigator.userAgent.indexOf("Chrome")>-1){
        console.log("I am Chrome");
    }
    
    console.log(document.URL);

},false)

<!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>
        <button id="promptBtn">打开提示页面</button>
        <div>
            <label>提示文字:</label><p id="text"></p>
        </div>
    </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;
}