window对象
不但充当全局作用域,而且表示浏览器窗口。
window对象有innerWidth和innerHeight属性,可以获取浏览器窗口的内部宽度和高度。内部宽高是指除去菜单栏、工具栏、边框等占位元素后,用于显示网页的净宽高。
还有一个outerWidth和outerHeight属性,可以获取浏览器窗口的整个宽高。
屏幕可用工作区高度:window.screen.availHeight
屏幕可用工作区宽度:window.screen.availWidth
Navigator对象
navigator对象表示浏览器的信息,最常用的属性包括:
•navigator.appName:浏览器名称;---------谷歌,火狐和360安全浏览器Netscape ,IE的值为Microsoft Internet Explorer
•navigator.appVersion:浏览器版本;
•navigator.language:浏览器设置的语言;--- zh-CN
•navigator.platform:操作系统类型;
•navigator.userAgent:浏览器设定的User-Agent字符串。
谷歌:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
火狐:
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0
IE:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3; Tablet PC 2.0)
screen
screen对象表示屏幕的信息,常用的属性有:
•screen.width:屏幕宽度,以像素为单位;
•screen.height:屏幕高度,以像素为单位;
•screen.colorDepth:返回颜色位数,如8、16、24。
Location 对象属性
以这个为例 http://example.com:1234/test/test.htm#part2
属性 | 描述 |
hash | 设置或返回从井号 (#) 开始的 URL(锚)。 #path2 |
host | 设置或返回主机名和当前 URL 的端口号。Example.com:1234 |
设置或返回当前 URL 的主机名。Example.com | |
href | 设置或返回完整的 URL。http://example.com:1234/test/test.htm#part2 |
设置或返回当前 URL 的路径部分。/test/test.htm | |
port | 设置或返回当前 URL 的端口号。1234 |
设置或返回当前 URL 的协议。http: | |
search | 设置或返回从问号 (?) 开始的 URL(查询部分)。?id=xxx |
Location 对象方法
属性 | 描述 |
加载新的文档。location.assign(URL) | |
重新加载当前文档。 | |
用新的文档替换当前文档。location.replace(newURL) |
假设当前的 URL 是: http://example.com:1234/test/test.htm#part2:
hash的值为#part2
pathname 的值为 /test/test.htm
host 的值为example.com:1234
hostname 的值为example.com
href 的值为 http://example.com:1234/test.htm#part2