JavaScript-manipulate BOM objects

JavaScript-manipulate BOM objects

BOM: Browser Object Model

windows object

The Window object represents the window opened in the browser, and the Window object also implements all the global properties and methods defined by the core JavaScript

window object usage

window.alert("跨年晚会")
undefined
window.innerHeight 窗口内高
137
window.innerWidth 窗口内宽
1360
window.outerHeight 窗口外高
768
window.outerWidth 窗口外宽
1496

navigator object

Encapsulates the browser information (not commonly used, because it will be artificially modified)

navigator.appName  //浏览器名称
"Netscape"
navigator.appVersion  //浏览器版本
"5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3706.400 SLBrowser/10.0.4040.400"
navigator.userAgent  //声明了浏览器用于 HTTP 请求的用户代理头的值
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3706.400 SLBrowser/10.0.4040.400"

Screen object

Contains information about the client's display screen.

//屏幕尺寸
screen.height
864 px
screen.width
1536 px

Location object

URL information representing the current page

//信息
host: "www.bilibili.com"  主机
href: "https://www.bilibili.com/"  当前位置
protocol: "https:" 协议
//方法
reload: ƒ reload()  刷新网页
//设置新的链接地址,然后定位到新链接
location.assign('https://mp.csdn.net/console/home?spm=1001.2101.3001.4503')

document object

Represents the current page, and every HTML document loaded into the browser becomes a Document object.

查询和新修改页面标题
document.title
"首页-CSDN博客"
document.title="万里顾一程"
"万里顾一程"

获取具体的文档树节点
<dl id="app">
    <dt>Java</dt>
    <dd>JAVAEE</dd>
    <dd>JAVASE</dd>
</dl>
<script>
    var dl = document.getElementById('app');
</script>

Get cookie (data stored on the user's local client)

document对象可以设置或返回与当前文档有关的所有 cookie
document.cookie

Insert picture description here

history object

The History object contains URLs visited by the user (in the browser window)

//方法
back()	加载 history 列表中的前一个 URLforward()	加载 history 列表中的下一个 URL

Guess you like

Origin blog.csdn.net/wpc2018/article/details/111706048