window对象

JavaScript可以获取浏览器提供的很多对象,并进行操作。

window对象不但充当全局作用域,而且表示浏览器窗口。

window对象有innerWidth和innerHeight属性,可以获取浏览器窗口的内部宽度和高度。内部宽高是指除去菜单栏、工具栏、边框等占位元素后,用于显示网页的净宽高。

兼容性:IE<=8不支持。

对应的,还有一个outerWidth和outerHeight属性,可以获取浏览器窗口的整个宽高。

navigator对象(表示浏览器的信息)

最常用的属性包括:

  • navigator.appName:浏览器名称;

  • navigator.appVersion:浏览器版本;

  • navigator.language:浏览器设置的语言;

  • navigator.platform:操作系统类型;

  • navigator.userAgent:浏览器设定的User-Agent字符串。

screen对象(表示屏幕的信息)

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

location对象(表示当前页面的url信息)

一个完整的URL可以用location.href获取。要获取URL各个部分的值,可以这么写:

http://www.example.com:8080/path/index.html?a=1&b=2#TOP

location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'

 

posted @ 2018-07-30 16:45  飞鱼0725  阅读(133)  评论(0编辑  收藏  举报