BOM和DOM
BOM 是浏览器对象模型,DOM是文档对象类型。
window对象
window
对象代表了浏览器窗口,而DOM中的document 对象也是window对象属性。
获得浏览器窗口尺寸:
//适用于所有浏览器:
window.innerWidth || document.documentElement.clientWidth
|| document.body.clientWidth;
window.innerHeight || document.documentElement.clientHeight
|| document.body.clientHeight;
screen对象
screen
对象代表了用户屏幕信息。
获得屏幕尺寸:
screen.height 和 screen.width
可用尺寸:
//访问者屏幕的宽度,以像素计,减去诸如窗口工具条之类的界面特征。
screen.availWidth 和 screen.availHeight
location对象
window.location
对象可以获取当前页面的URL地址并重定向。
window.location.href
返回当前页面的 href (URL)window.location.hostname
返回web 主机的域名window.location.pathname
返回当前页面的路径或文件名window.location.protocol
返回使用的 web 协议(http: 或 https:)window.location.assign
加载新文档
history对象
window.history
对象代表浏览器历史。
history.back()
加载历史列表前一个URL,后退history.forward()
加载历史列表下一个URL,前进