10-BOM操作

182 阅读1分钟

题目

- 如何识别浏览器的类型
- 分析拆解url各个部分
  • 如何识别浏览器的类型
const ua = navigator.userAgent
const isChrome = ua.indexOf('Chrome')
console.log(isChrome)
  • 分析拆解url各个部分
console.log(location.href)
console.log(location.protocol)
console.log(location.pathname)
console.log(location.search)
console.log(location.hash)

分析:www.baidu.com/?a=2&b=3#ac…

image.png

知识点

  • navigator
  • screen
  • location
  • history

navigator 和 screen

//navigator
const ua = navigator.userAgent
const isChrome = ua.indexOf('Chrome')
console.log(isChrome)

//screen
console.log(screen.width)
console.log(screen.height)

location和history

//location
console.log(location.href)
console.log(location.protocol)
console.log(location.pathname)
console.log(location.search)
console.log(location.hash)

//history
history.back()
history.forward()