BOM操作

2018-12-10  本文已影响0人  陈裔松的技术博客

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();  // 前进
上一篇下一篇

猜你喜欢

热点阅读