BOM --- 大致记忆一些API

128 阅读1分钟

BOM浏览器对象模型

BOM:浏览器对象模型,用于窗口与窗口之间的交互,提供了当前独立于内容而与窗口进行交互的对象。核心对象为window。window对象是全局对象,有自己的属性和方法。

window对象常用的属性

  • window.document:返回当前窗口所包含文档的引用 window.document.PNG
  • window.history:返回对history对象的引用 window.history.PNG
  • window.innerHeight / window.innerWidth :获取窗口内容区域的高度和宽度 innerHeight+innerWidth.PNG
  • window.location:获取location对象的引用或者当前的URL window.location.PNG
  • window.navigator:返回对navigator对象的引用 window.navigator.PNG
  • window.outerHeight / window.outerWidth :返回窗口外部的高度和宽度 outerHeight+outerWidth.PNG
  • window.screen:返回对屏幕的的引用 window.screen.PNG
  • window.scrollX / window.scrollY 返回文档水平滚动的像素和垂直滚动的像素 scrollX + scrollY.PNG

window对象常用的方法

  • window.alert()
  • window.prompt()
  • window.close()
  • window.confirm()
  • window.open():打开一个新的窗口
  • setTimeout(函数, 时间) // 定时器,只执行一次
  • clearTimeout(定时器名称) // 清除计时器
  • setInterval(函数,时间) // 定时器,无限执行
  • clearInterval() // 停止执行 setInterval()

location对象

Location接口表示其连接到对象的地址(URL),具有:Document.location / Window.location

  1. 常用的属性
  • location.href // url
  • location.port // 端口号
  • location.host // 域名 + 端口号
  • location.hostname // 域名
  • location.search // 查询字符串
  • location.hash // hash值
  • location.username
  • location.password
  • location.origin // url
  1. 常用的API
  • location.replace()
  • location.reload() //重新加载

navigator对象

navigator对象表示用户代理的状态和标识。

  • navigator.useragent // 查看浏览器的内核

history

history许接口允许操作浏览器的曾经在标签页或者框架里访问的会话历史记录。

  1. 常用属性
  • history.state :返回栈顶的状态值
  1. 常用方法
  • history.back() = history.go(-1) //后退一页
  • history.forward() = history.go(1) //浏览器历史记录中的往前一页
  • history.pushState():推进历史记录中一条数据
  • history.replaceState(): 替换当前数据

screen对象,标识屏幕的一个窗口,往往指的是正在渲染的window对象。

  • screen.height
  • scrren.width