JS学习-浏览器对象

来源:互联网 发布:unity3d卡牌游戏技能 编辑:程序博客网 时间:2024/05/16 10:38

window

window对象不仅作为全局作用域,也表示浏览器的窗口

  • innerWidthinnerHeight:表示浏览器窗口的内部宽度和高度。内部宽高是指除去菜单栏、工具栏、边框等占位元素后,用于显示网页的净宽高
  • outerWidthouterHeight:浏览器窗口的整个宽高

navigator对象表示浏览器的信息。

  • navigator.appName:浏览器名称
  • navigator.appVersion:浏览器版本
  • navigator.language:浏览器语言
  • navigator.platform:浏览器系统类型
  • navigator.userAgent:浏览器用户代理
    注意:navigator的信息可以很容易地被用户修改,所以JavaScript读取的值不一定是正确的。正确的方法是充分利用JavaScript对不存在属性返回undefined的特性,直接用短路运算符||计算

screen

screen对象表示屏幕的信息

  • screen.width:屏幕宽度,像素为单位
  • screen.height:屏幕高度,像素为单位
  • screen.colorDepth:返回颜色位数,如8、16、24

location

location对象表示当前页面的URL信息

//一个完整的url路径http://www.example.com:8080/path/index.html?a=1&b=2#TOPlocation.protocol; // 'http'location.host; // 'www.example.com'location.port; // '8080'location.pathname; // '/path/index.html'location.search; // '?a=1&b=2'location.hash; // 'TOP'

document

document对象表示当前页面。由于HTML在浏览器中以DOM形式表示为树形结构,document对象就是整个DOM树的根节点

原创粉丝点击