JS-Web-API-BOM

知识点

navigator 浏览器的信息

screen 屏幕的信息

location 地址的信息

history 前进后退的信息

// navigator
const ua = navigator.userAgent
const isChrome = ua.indexOf('Chrome') // 判断是否为Chrome浏览器
console.log('isChrome',isChrome)
​
// screen
// 打印屏幕的宽 & 高
console.log(`screen.width: ${screen.width} ; screen.height: ${screen.height}`);
​
// location
console.log(location.href);
console.log(location.protocol); // 'http:' 'https:'
console.log(location.host);
console.log(location.pathname); // '/learn/199'
console.log(location.search);
console.log(location.hash);
​
// history
history.back() // 后退
history.forward() // 前进

题目

如何识别浏览器类型

navigator.userAgent

分析拆解url各个部分

  • location.href:整个网址

  • location.protocol:使用的协议,比如'https:'、‘http:’

  • location.host:域名

  • location.pathname:路径

  • lccation.search:获取url的query参数

  • location.hash:去url的hash值,比如'#list'

posted @ 2021-01-20 23:28  倦梦还  阅读(61)  评论(0编辑  收藏  举报