一、BOM常用api
1、navigator
查询浏览器类型
let ua = navigator.useragent;
const isChrome = us.indexof( ‘chrome’ );
浏览器为了兼容更多网站,会在ua中添加很多浏览器名
2、screen
查询设备屏幕宽高(与窗口大小无关)
screen.width; screen.height
3、location
url结构: ‘https://baidu.com/index.html?keyword=frank#hashValue‘
(1)协议 location.protocal
(2)域名 location.href 通过dns服务器转化为ip地址
(3)路径 location.pathname 资源路径
(4)查询参数 location.query
(5)哈希值 location.hash 位置标志符—告诉浏览器访问页面特定部分(像书签)onhashchange可以监听,哈希改变不会触发网页重载。
4、history
控制浏览器访问记录
history.go()
history.forward()
history.back()