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"
获取网页之中的具体的文档树节点
<!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,您的支持作者最大的创作动力哟! <(^-^)>
才疏学浅,若有纰漏,恳请斧正
本文章仅用于各位同志作为学习交流之用,不作任何商业用途,若涉及版权问题请速与作者联系,望悉知