Navigator 对象
如何识别浏览器的类型?
const ua=navigator.userAgent
const isChrome =ua.indexOf('Chrome')
console.log(ua) // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
console.log(isChrome)
Screen 对象
console.log(screen)
console.log(screen.width) //返回显示器屏幕的宽度。
console.log(screen.height)//返回显示器屏幕的高度。
Location 对象
分析拆解URL的各个部分?
console.log(location.href) // file:///Users/xiaolo/learn/js_basics/7-BOM/7-1.html?id=2#00 完整的 URL。
console.log(location.protocol) // 当前 URL 的协议 file:
console.log(location.host) // 当前 URL 的域名:
console.log(location.pathname)// 当前 URL 的路径部分 /Users/xiaolo/learn/js_basics/7-BOM/7-1.html
console.log(location.search) //从问号 (?) 开始的 URL ?id=2
console.log(location.hash) //从井号 (#) 开始的 URL(锚) #00
History 对象
history.back() //加载 history 列表中的前一个 URL。
history.forward()//加载 history 列表中的下一个 URL。
history.go()//加载 history 列表中的某个具体页面。