BOM(Browser Object Model)
题目
如何识别浏览器的类型
var ua = navigator.userAgent
var isChrome = ua.indexOf('Chrome')
console.log(isChrome)
分析拆解url各个部分
//location
console.log(location.href) //整个URL
console.log(location.protocol) // 协议 ('http:','https:')
console.log(location.host) // 域名
console.log(location.pathname) // 域名后'/learn/199'
console.log(location.search) // ?后的参数
console.log(laoction.hash) // #后的哈希
知识点
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) //整个URL
console.log(location.protocol) // 协议 ('http:','https:')
console.log(location.pathname) // 域名后'/learn/199'
console.log(location.search) // ?后的参数
console.log(laoction.hash) // #后的哈希
// history
history.back() //返回
history.forward() //前进后退