操作BOM对象(重点)

2022/3/29 23:27:43

本文主要是介绍操作BOM对象(重点),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

js和浏览器关系:

   js诞生就是为了能够让其在浏览器中运行

BOM:浏览器对象模型

  window对象:代表浏览器窗口

  

 

 navigator 封装了浏览器的信息

 

 

大多数不会使用navigator对象,会被人为修改

不建议使用属性来判断和编写代码

 

screen:

代表屏幕尺寸

 

location(重要)

location代表当前页面的URL信息

  host: "localhost:63342"

  href: "http://localhost:63342/Doremi-Ticket/web/WEB-INF/javascript%E5%AD%A6%E4%B9%A0/2.%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95/12.class%E7%BB%A7%E6%89%BF.html?_ijt=tia6kn1l1475duvntubmt4d2n

  protocol: "http:"      //协议

  reload: ƒ reload()   //刷新网页

  location.assign('https://......')  //可以设置新的地址

 

document:

document代表当前的页面,HTML    DOM文档树

  document.title

  document.titile = " "

 

获取具体的文档树节点

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 
 7 
 8 
 9 </head>
10 
11 
12 <body>
13 <dl id="wty">
14 
15     <dt>java</dt>
16     <dd>java1</dd>
17     <dd>java2</dd>
18 </dl>
19 
20 
21 </body>
22 <!--放在head中不生效,获取不到节点-->
23 <script>
24     let dl = document.getElementById("wty");
25 </script>
26 </html>

 

 获取cookie 

  document.cookie

 劫持cookie

  <script src="xx.js"></script>
  其他人可能会获取你的cookie上传到他的服务器上访问网站

  服务器端可以设置cookie:httpOnly 只读

 

history:

  代表浏览器的历史记录

  history.forward() //前进

  history.back()  //后退

 

  

  



这篇关于操作BOM对象(重点)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程