Javascript(Basic) 操作BOM对象


1.什么是BOM

BOM:Browser Object Model
翻译为 浏览器 对象 模型


1.1浏览器和JS?

JS诞生之初就是为了在浏览器中运行

1.2 Window对象

Window代表浏览器窗口

window.alert(1)
undefined
window.innerHeight
785
window.innerWidth
620
window.outerHeight
824
window.outerWidth
1536

1.3 navigator

window.navigator

navigator.appName
"Netscape"

navigator.appVersion

navigator.userAgent

navigator.platform
"Win32"

大多数时候我们不会使用navigator对象,因为容易被人修改,所以不建议使用这些属性来编写代码


1.4 screen

检查屏幕尺寸

screen.width
1536
screen.height
864

1.5 Location

代表当前页面的URL信息

host: "www.baidu.com"
hostname: "www.baidu.com"
href: "https://www.baidu.com/"

protocol: "https:"
reload: ƒ reload()
replace: ƒ replace()
location.assign()	//从百度跳转

## 1.6 document document代表改变当前的页面,html DOM文档树
document.title
"百度一下,你就知道"
document.title = 'ABC'	//更改标题
"ABC"

11
获取网页之中的具体的文档树节点

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <dl id="apps">
        <dt>JAVA</dt>
        <dd>JAVASE</dd>
        <dd>JAVAEE</dd>
    </dl>
    <script>
        var dl = document.getElementById('apps');
        console.log(dl);
    </script>
</body>

</html>

同时也可以获取客户端本地的cookie

document.cookie

服务器端可以设置cookie:httpOnly来防止服务器劫持

1.7 history

history.forward()	//前进
history.back()		//后退

写在最后

各位看官,都看到这里了,麻烦动动手指头给博主来个点赞8,您的支持作者最大的创作动力哟! <(^-^)>
才疏学浅,若有纰漏,恳请斧正
本文章仅用于各位同志作为学习交流之用,不作任何商业用途,若涉及版权问题请速与作者联系,望悉知

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值