js操作BOM

什么是Bom?

Bom是浏览器对象。它提供与浏览器的交互5大属性。

有哪些常用的Bom属性呢?

在这里插入图片描述

navigator(浏览器对象)

1. 如何检测浏览器的类型 (ua的问题)?

//如何检测是否为Chrome浏览器
var ua = navigator.userAgent;
console.log(ua);
var isChrome =ua.indexOf('Chrome');
console.log(isChrome); // true为是,false为不是

在这里插入图片描述

screen(屏幕对象)

screen.width;//屏幕宽度
screen.height; //屏幕高度

location (地址对象)

解析url?

location.href-- 返回或设置当前文档的URL
location.search -- 返回URL中的查询字符串部分。例如 http://www.dreamdu.com/dreamdu.php?id=5&name=dreamdu 返回包括(?)后面的内容?id=5&name=dreamdu
location.hash -- 返回URL#后面的内容,如果没有#,返回空
location.host -- 返回URL中的域名部分,例如www.dreamdu.com
location.hostname -- 返回URL中的主域名部分,例如dreamdu.com
location.pathname -- 返回URL的域名后的部分。例如 http://www.dreamdu.com/xhtml/ 返回/xhtml/
location.port -- 返回URL中的端口部分。例如 http://www.dreamdu.com:8080/xhtml/ 返回8080
location.protocol -- 返回URL中的协议部分。例如 http://www.dreamdu.com:8080/xhtml/ 返回(//)前面的内容http:
location.assign -- 设置当前文档的URL
location.replace() -- 设置当前文档的URL,并且在history对象的地址列表中移除这个URL location.replace(url);
location.reload() -- 重载当前页面

history(历史对象)

history.go() //前进或后退指定的页面数 history.go(num);
history.back()// 后退一页
history.forward() // 前进一页

面试题:

  1. 如何检测浏览器版本(ua检测)?
  2. 解析url
  3. 返回上一页?
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

star@星空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值