javascript 浏览器对象

1.window对象

innerWidthinnerHeight属性表示净宽高

outerWidthouterHeight属性表示浏览器窗口的整个宽高。

2.navigator

navigator.appName:浏览器名称;

navigator.appVersion:浏览器版本;

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

navigator.platform:操作系统类型;

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

navigator的信息可以很容易地被用户修改,准确获得浏览器宽度

var width = window.innerWidth || document.body.clientWidth;

3.screen 

screen.width:屏幕宽度,以像素为单位;

screen.height:屏幕高度,以像素为单位;

screen.colorDepth:返回颜色位数,如8、16、24。

4.location

location.href :获取完整网址

location.assign():加载新页面

location.reload():重载页面

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'

5.document 

document对象就是整个DOM树的根节点

documenttitle属性是从HTML文档中的<title>xxx</title>读取的,但是可以动态改变

document对象提供的getElementById()getElementsByTagName(),getElementsByClassName()获取页面元素

document.cookie读取到当前页面的Cookie:

使用querySelector()querySelectorAll()

// 通过querySelector获取ID为q1的节点:
var q1 = document.querySelector('#q1');

// 通过querySelectorAll获取q1节点内的符合条件的所有节点:
var ps = q1.querySelectorAll('div.highlighted > p');

6.history

history对象的back()forward ()控制网页前进后退(不要使用)

猜你喜欢

转载自blog.csdn.net/qq_32018951/article/details/81835678