南大软院大神养成计划第十五天



           今天的代码包括了计时器,页面跳转,查看浏览器信息这几个方面,运行起来的效果不好,代码还有待改善,先贴出来吧

<!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" οnclick="startCount()" />
    <input type="button" value="Stop"  οnclick="stopCount()" />
  </form>


使用下面按钮,实现页面跳转:
    <form>
       <input type="button"  value="返回前一个页面" οnclick="GoBack();" />      
       <input type="button"  value="返回下一个页面" οnclick="GoForward()" />  
       <input type="button" value="查看浏览器" οnclick="validB()"   >
    </form>
 
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值