操作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() //後退