当前位置:网站首页>DOM相关的方法概念
DOM相关的方法概念
2022-07-24 03:36:00 【勇敢*牛牛】
DOM相关的方法概念
window对象
跳转到其他浏览器
window.open('http://www.163.com')
关闭窗口
close()
浏览器窗口的内部高宽度(兼容所有浏览器)—包含滚动条
可以获取浏览器窗口的整个宽高
console.log(innerWidth,innerHeight);//document可视化窗口
console.log(outerWidth,outerHeight);//window窗口高度
浏览器窗口相对于电脑窗口的位置
screenLeft,screenTop ,screenX ,screenY
location.href=‘’跳转页面
window.location.href ='http://www.163.com'
location对象
点击按钮,跳转页面
<body>
<button id="demo">点击跳转页面</button>
<script>
location.assign('https://www.baidu.com/')
//获取标签元素
var bn = document.getElementById('demo');
bn.onclick = function(){
location.href = 'http://www.163.com'
location.assign('https://www.baidu.com/')
//注意这里的replace是没有历史记录的
location.replace('http://www.163.com')
}
</script>
获取当前网页的地址
<body>
<button id="demo">点击跳转页面</button>
<script>
var bn = document.getElementById('demo');
bn.onclick = function(){
console.log(location.href);
}
</script>
</body>
//http://127.0.0.1:5500/bomtest.html
hash获取到url中#后的字符串,如果没有,则返回空字符串。
search获取到url中?后的字符串,且不获取#后之后的值如果没有,则返回空字符串。
console.log(location.search);//?a=1&b=2
console.log(location.hash);//#abc
点击按钮跳转页面的同时带上内容,并接收解析
<button id="demo_1">a</button>
<button id="demo_2">b</button>
<button id="demo_3">c</button>
<button id="demo_4">d</button>
<script>
var nbs = Array.from(document.getElementsByTagName('button'))
for(var i=0;i<nbs.length;i++){
nbs[i].onclick = fun;
}
function fun(){
// 跳转页面附带对象内容的值
location.href = './index.html?key='+this.innerHTML;
}
</script>
注意:锚点链接会有一个历史记录,跳转到上(下)一次的位置。
| 方法 | 功能 |
|---|---|
| hostname | 返回 web 主机的域名手机 |
| pathname | 返回当前页面的路径和文件名 |
| port | 返回 web 主机的端口 (80 或 443) |
| protocol | 返回所使用的 web 协议(http:// 或 https://) |
screen对象
console.log(screen.availWidth);//不包含任务栏
console.log(screen.Width);//包含任务栏
获取定位:
navigator.geolocation.getCurrentPosition(function(pos){
console.log(pos);//真实定位
},function(err){
// 要么就是报错
})
history对象
有历史记录不需要重新渲染页面
SSR SEO搜索优化 Server Side Render
CSR 单页面渲染 Client Side Render
history.back();
history.forward();
history.go(0);//刷新
history.go(-1);//回退一个
history.go(1);//前进一个
var div = document.getElementById('d1')
div.onclick = fn;
function fn(){
history.go(0);//刷新
}
添加状态
替换状态
获取状态数据
history.pushState({
a:1},'a','#a')
history.replaceState({
btoa:1},'a','#a')
console.log(history.state);
边栏推荐
- Xiaodi and Xiaohui
- Express内置的中间件
- Read and understand the advantages of the LAAS scheme of elephant swap
- Tetris, 1
- C动态内存管理详解
- 【云原生】快速了解Kubernetes
- Skywalking distributed system application performance monitoring tool - upper
- leetcode hot 100(刷题篇8)(232/88/451/offer10/offer22/344/)
- 93. (leaflet chapter) leaflet situation plotting - modification of attack direction
- C user defined type details
猜你喜欢

C文件操作详解

Programmers may still be programmers, and coders may only be coders

Talk about the application of FIFO

idea写web项目时报错Failed to load resource: the server responded with a status of 404 (Not Found)

How emqx 5.0 under the new architecture of mria + rlog realizes 100million mqtt connections

QT custom class uses custom parametric signals and slots

93. (leaflet chapter) leaflet situation plotting - modification of attack direction

Qt自定义类使用自定义含参信号与槽

Write code, and multiple characters move from both ends to converge in the middle

Technical dry goods | evaluation index based on mindspire detailed perflexity language model
随机推荐
B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
水题: 接雨水
Why do some people write code so complicated?
CVE-2022-29464 WSO2文件上传漏洞
You must know the ten vulnerabilities of invalid access control
[interpolation expression of applet, rendering judgment, binding events and sharing]
The error of van swipe in the rotation chart: cannot read a properties of null (reading width)
An in-depth explanation of CAS is necessary for interview practice
Advantages, disadvantages and summary of sequence list and linked list
Using global data to realize data sharing in wechat applet
IDEA Clone的项目报Cannot resolve symbol ‘Override‘
Gpushare.com | 如何使用TensorBoardX可视化工具?
How to efficiently install the GPU version of mindspire
Data Lake: comparative analysis of open source data Lake schemes deltalake, Hudi and iceberg
Svn: e00002: can't convert string from 'UTF-8' to native encoding problem solving
Water topic: connect rainwater
Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)
C. Minimum Ties-Educational Codeforces Round 104 (Rated for Div. 2)
C文件操作详解
Express内置的中间件