JavaScript浏览对象(笔记)

来源:互联网 发布:linux服务器慢的原因 编辑:程序博客网 时间:2024/06/05 15:15

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

window

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

navigator对象表示浏览器的信息,最常用的属性包括:

navigator.appName:浏览器名称;navigator.appVersion:浏览器版本;navigator.language:浏览器设置的语言;navigator.platform:操作系统类型;navigator.userAgent:浏览器设定的User-Agent字符串。

screen

screen对象表示屏幕的信息,常用的属性有:

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

location

location对象表示当前页面的URL信息。例如,一个完整的URL,可以用location.href获取。

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

要获得URL各个部分的值,可以这么写:

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'

document

document对象表示当前页面。由于HTML在浏览器中以DOM形式表示为树形结构,document对象就是整个DOM树的根节点。
document对象提供的getElementById()getElementsByTagName()可以按ID获得一个DOM节点和按Tag名称获得一组DOM节点
document对象还有一个cookie属性,可以获取当前页面的Cookie。

history

历史遗留对象,不建议使用。

原创粉丝点击