南大軟院大神養成計劃第十五天



           今天的代碼包括了計時器,頁面跳轉,查看瀏覽器信息這幾個方面,運行起來的效果不好,代碼還有待改善,先貼出來吧

<!DOCTYPE  HTML>

<html >

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>瀏覽器對象</title>
<script type="text/javascript">
//計時器
  var num=0;
  var i;
  function startCount(){
    document.getElementById('count').value=num;
    num=num+1;
    i=setTimeout("startCount()",1000);
  }
  function stopCount(){
    clearTimeout(i);
  }


//History 對象,記錄了用戶曾經瀏覽過的頁面(URL),並可以實現瀏覽器前進與後退相似導航的功能。
var HL = window.history.length;
  document.write(HL);//使用length屬性,顯示當前窗口的瀏覽歷史總長度
   function GoBack() {
        window.history.back();   
        }//返回前一個瀏覽頁面
 function GoForward() {
        window.history.forward();   
        }//返回下一個瀏覽頁面


//location用於獲取或設置窗體的URL,並且可以用於解析URL。
    document.write(window.location.href);

//navigator  查看瀏覽器相關信息
var browser = navigator.appName;
  var version = navigator.appVersion;
  var appCode = navigator.appCodeName;
  var platSys = navigator.platform;
  var usersAg = navigator.userAgent;
  document.write("瀏覽器名稱:"+browser+"<br />"+"平臺和版本信息:"+version+"<br />"+"瀏覽器代碼名稱字符:"+appCode+"<br />"+"瀏覽器操作系統平臺:"+platSys+"<br />"+"服務器頭部的值:"+usersAg)


 //userAgent返回用戶代理頭的字符串表示(就是包括瀏覽器版本信息等的字符串)
function validB(){
    var u_agent =navigator.userAgent ;
    var B_name="不是想用的主流瀏覽器!";
    if(u_agent.indexOf("Firefox")>-1){
        B_name="Firefox";
    }else if(u_agent.indexOf("Chrome")>-1){
        B_name="Chrome";
    }else if(u_agent.indexOf("MSIE")>-1&&u_agent.indexOf("Trident")>-1){
        B_name="IE(8-10)"; 
    }
        document.write("瀏覽器:"+B_name+"<br>");
        document.write("u_agent:"+u_agent+"<br>");
  }

//screen對象用於獲取用戶的屏幕信息
document.write( "屏幕寬度:"window.screen.width+"px");
document.write( "屏幕高度:"window.screen.height+"px");     

//獲取用戶屏幕可用寬度和高度
document.write("可用寬度:"screen.availWidth+"px<br/>"  );
document.write("可用高度:"screen.availHeight+"px<br/>"  );    

 </script>

 </head>

 <body>


  <form>

    <input type="text" id="count" />

    <input type="button" value="Start" onclick="startCount()" />
    <input type="button" value="Stop"  onclick="stopCount()" />
  </form>


使用下面按鈕,實現頁面跳轉:
    <form>
       <input type="button"  value="返回前一個頁面" onclick="GoBack();" />      
       <input type="button"  value="返回下一個頁面" onclick="GoForward()" />  
       <input type="button" value="查看瀏覽器" onclick="validB()"   >
    </form>
 
</body>

</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章