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