BOM操作

BOM(Browser Object Model):浏览器对象模型

navigator 浏览器

检查浏览器特性:navigator.userAgent

var ua = navigator.userAgent;
var isChrome = ua.indexOf('Chrome');

console.log(ua);
// Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
console.log(isChrome);  // 76

screen 屏幕

console.log(screen.width);  // 1536 获取屏幕宽度
console.log(screen.height); // 864  获取屏幕高度

location 地址

例子1:http://erp.jiahenghealth.com/#/contracts/list?currPageNo=1&limit=10&

console.log(location.href);     // 整个地址:"http://erp.jiahenghealth.com/#/contracts/list?currPageNo=1&limit=10&"
console.log(location.protocol); // 协议:"http:"
console.log(location.host);     // 域名:"erp.jiahenghealth.com"
console.log(location.pathname); // 路径:"/"
console.log(location.search);   // 搜索:""
console.log(location.hash);     // 哈希:"#/contracts/list?currPageNo=1&limit=10&"

例子2:https://tieba.baidu.com/index.html?traceid=

console.log(location.href);     // 整个地址:"https://tieba.baidu.com/index.html?traceid="
console.log(location.protocol); // 协议:"http:"
console.log(location.host);     // 域名:"tieba.baidu.com"
console.log(location.pathname); // 路径:"/index.html"
console.log(location.search);   // 搜索:"?traceid="
console.log(location.hash);     // 哈希:""

history 历史

history.back();  // 后退
history.forwarc();  // 前进
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容