JavaScript學習筆記十三 —— 操作BOM對象
參考教程B站狂神https://www.bilibili.com/video/BV1JJ41177di
BOM:瀏覽器對象模型
window窗口
window.alert(1) //彈窗
window.innerHeight //內部高度
window.innerWidth //內部寬度
window.outerWidth //外部高度
window.outHeight //外部高度
navigator
Navigator,封裝了瀏覽器的信息
大多數時候不會使用navigator對象,因爲會被人爲修改
navigator
[object Navigator]: {activeVRDisplays: Array, appCodeName: "Mozilla", appName: "Netscape", appVersion: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362", cookieEnabled: true...}
navigator.appName
"Netscape"
navigator.appVersion
"5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"
navigator.userAgent
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"
navigator.platform
"Win32"
screen 屏幕
screen.height
screen.width
location
location 代表當前頁面的url信息
host: "www.baidu.com" 主機
href: "https://www.baidu.com/" 當前指向位置
protocol: "https:" 協議
reload: ƒ reload() 刷新網頁
//設置新地址,放上這段代碼後,打開原來的網站就會跳轉到你填寫的鏈接的網站了
location.assign('url')
document
document 代表當前的頁面,HTML DOM文檔
document.title
"百度一下,你就知道"
document.title = 'yinglongwu' //修改標題
"yinglongwu"
獲取具體的文檔樹節點
<dl id = "app">
<dt>java</dt>
<dd>javaEE</dd>
<dd>javaSE</dd>
</dl>
<script>
var dl = document.getElementById('app');
</script>
獲取cookie
document.cookie
cookie 可以被劫持,從而獲取你的一些信息,如用戶名、密碼等
服務器端可以設置cookie爲 httpOnly ,就比較安全
history
history代表瀏覽器的歷史記錄
偷懶行爲,不建議使用
history.back() //網頁後退
history.forward() //網頁前進