1.window对象
innerWidth
和innerHeight
属性表示净宽高
outerWidth
和outerHeight
属性表示浏览器窗口的整个宽高。
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树的根节点
document
的title
属性是从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 ()控制网页前进后退(不要使用)