SOURCE

console 命令行工具 X clear

                    
>
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>,我是新的窗口</p></div>";
        oNewWin.document.body.style.color="red";

       // oNewWin.setTimeout(function(){
       //         oNewWin.document.URL="http://www.sina.com.cn";
       // },2000);
        //空白页面重新定位
        //过两秒打开设定的网址新浪
        console.log(oNewWin.location.href);
        oNewWin.setTimeout(function(){
            oNewWin.location.href="http://www.sina.com.cn";
        },2000);

        
    })
    //打印一下location
    console.log("line30:"+window.location.href);
    console.log("line31:"+window.location.search);
    console.log("line32:"+window.location.hash);
    console.log("line37:"+window.document.URL);

    //关闭窗口
    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("http://www.baidu.com");
        }
    });
    //打开提示窗口
     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;
        }
    });
    //轮播图
    var oStopTimeBtn=this.document.getElementById("stopTimer");
    var oStartTimeBtn=this.document.getElementById("startTimer");
    var oTimeBox=this.document.getElementById("timerBox");
   var oTimer;
    oStartTimeBtn.addEventListener("click",function(){
      if(oTimer){
          window.clearTimeout(oTimer);
        }
       oTimer=window.setTimeout(function(){
            oTimeBox.style.backgroundColor="blue";
       },2000); 
    });
       oStopTimeBtn.addEventListener("click",function(){
           if(oTimer){
               window.clearTimeout(oTimer);
           }
        });

    var oStopIntervalBtn=this.document.getElementById("stopInterval");
    var oStartIntervalBtn=this.document.getElementById("startInterval");
    var oIntervalBox=this.document.getElementById("intervalBox");
    var oIntervalText=this.document.getElementById("intervalText");
    var oInterval;
    var count=5;
    oIntervalText.innerHTML=count;
    function changeColor(){
        var colors=["red","green","pink","yellow","lightskyblue"];
        if(count>0){
            count--;
            oIntervalBox.style.backgroundColor=colors[count];
            oIntervalText.innerHTML=count;
        }else{
            count=5;
        }
    }
    oStartIntervalBtn.addEventListener("click",function(){
      if(oInterval){
          window.clearInterval(oInterval);
        }
      oInterval=window.setInterval(changeColor,1000);
    });
       oStopIntervalBtn.addEventListener("click",function(){
           if(oInterval){
               window.clearTimeout(oInterval);
           }
        });
    //打印一下navigator
    console.log("Line119:"+window.navigator.userAgent);
    
    //navigator需要在不同浏览器里面打印
    //工具--开发员工具--控制台 
    //window.navigator.userAgent

})
<!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>
    </div>
    <br/>
    <div>
        <button id="promptBtn">打开提示窗口</button>
        <br/>
        <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;
}