js BOM

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,前进
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值