黑马程序员技术交流社区

标题: 使用javascript如何获取当前浏览器的相关属性 [打印本页]

作者: 蔡尚猛    时间: 2012-7-30 11:48
标题: 使用javascript如何获取当前浏览器的相关属性
使用javascript如何获取当前浏览器的相关属性;如:版本…………
作者: 陈汉维    时间: 2012-7-30 11:53
本帖最后由 陈汉维 于 2012-7-30 11:55 编辑

DOM--->document
BOM--->window
document对象是window的一个子对象或叫属性
window对象的子对象:
window.navigator 浏览器信息
window.location 地址栏(可以控制页面跳转)
window.history 历史记录(控制前进后退)
window.screen 屏幕(表示分辨率信息)
window.document DOM模型
navigator对象:
appCodeName 内部代码
appName 浏览器名称
appVersion 浏览器版本
platform 操作系统类型
userAgent 用户代理信息
cookieEnabled 是否支持cookie
history对象
length:历史记录的数目
back(); back(-1);后退一格
forward(); forward(1);前进一格
go();
location对象:
host 主机
port 端口
href 地址                  
pathname 路径
protocol 协议
search 查询字符串
assign(url) 页面跳转
screen对象:
height 高度
width 宽度
availHeight 可用高度   
availWidth 可用宽度
colorDepth 颜色
window对象的方法:
alert(message) 对话框
confirm(message) 确认框
prompt(‘提示信息’,’默认值’) 提示输入框
close() 关闭窗口
print() 打印
setInterval(表达式,毫秒);
clearIntval(定时器对象);
setTimeout(表达式,毫秒)
clearTimeout(定时器对象)
以上数据来源:传智播客十八哥的javascript视频
作者: 许庭洲    时间: 2012-7-30 13:33
<script type="text/javascript">
      var Sys = {};
      var ua = navigator.userAgent.toLowerCase();
      var s;
      (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
      (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
      (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
      (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
      (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
      //以下进行测试
     if (Sys.ie)
          document.write('IE: ' + Sys.ie);
     if (Sys.firefox)
          document.write('Firefox: ' + Sys.firefox);
     if (Sys.chrome)
          document.write('Chrome: ' + Sys.chrome);
     if (Sys.opera)
          document.write('Opera: ' + Sys.opera);
     if (Sys.safari)
          document.write('Safari: ' + Sys.safari);
</script>
作者: 唐兰文    时间: 2012-7-30 13:37
上面写的很清楚了,给你举个例子
<html>
<head>
    <title>页面属性获取</title>
    <script type="text/javascript">
        var a1=window.location.href;
        alert(a1);
    </script>
</head>
<body>

</body>
</html>




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2