当前位置:网站首页>DOM related method concepts
DOM related method concepts
2022-07-24 03:41:00 【Brave * Niuniu】
DOM Related method concepts
window object
Jump to another browser
window.open('http://www.163.com')
close window
close()
The internal height and width of the browser window ( Compatible with all browsers )— Include scroll bar
You can get the full width and height of the browser window
console.log(innerWidth,innerHeight);//document Visualization window
console.log(outerWidth,outerHeight);//window Window height
The position of the browser window relative to the computer window
screenLeft,screenTop ,screenX ,screenY
location.href=‘’ Jump to the page
window.location.href ='http://www.163.com'
location object
Click button , Jump to the page
<body>
<button id="demo"> Click to jump to the page </button>
<script>
location.assign('https://www.baidu.com/')
// Get tag elements
var bn = document.getElementById('demo');
bn.onclick = function(){
location.href = 'http://www.163.com'
location.assign('https://www.baidu.com/')
// Notice the replace There is no historical record
location.replace('http://www.163.com')
}
</script>
Get the address of the current web page
<body>
<button id="demo"> Click to jump to the page </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 Get url in # String after , without , Returns an empty string .
search Get url in ? String after , And don't get # If there is no value after , Returns an empty string .
console.log(location.search);//?a=1&b=2
console.log(location.hash);//#abc
Click the button to jump to the page and bring the content , And receive parsing
<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(){
// Jump to the value of the object content attached to the page
location.href = './index.html?key='+this.innerHTML;
}
</script>
Be careful : Anchor links will have a history , Jump to ( Next ) Once position .
| Method | function |
|---|---|
| hostname | return web The domain name of the host phone |
| pathname | Returns the path and filename of the current page |
| port | return web Host port (80 or 443) |
| protocol | Return to used web agreement (http:// or https://) |
screen object
console.log(screen.availWidth);// Does not contain taskbar
console.log(screen.Width);// Contains the taskbar
Get positioning :
navigator.geolocation.getCurrentPosition(function(pos){
console.log(pos);// True positioning
},function(err){
// Or you report an error
})
history object
There is no need to re render the page with history
SSR SEO Search optimization Server Side Render
CSR Single page rendering Client Side Render
history.back();
history.forward();
history.go(0);// Refresh
history.go(-1);// Back one
history.go(1);// Forward one
var div = document.getElementById('d1')
div.onclick = fn;
function fn(){
history.go(0);// Refresh
}
Add state
Replacement status
Get status data
history.pushState({
a:1},'a','#a')
history.replaceState({
btoa:1},'a','#a')
console.log(history.state);
边栏推荐
- Matlab Fractional Order PID control
- Conteneur STL set
- [wepy2.0] installation
- Data Lake (19): SQL API reads Kafka data and writes it to iceberg table in real time
- Method sharing of saving data to CSV file in MATLAB
- Introduction to pytorch ecology
- Redis transaction learning
- Istio architecture extension mechanism
- [interpolation expression of applet, rendering judgment, binding events and sharing]
- Convert the pseudo array returned by childNodes into a true array
猜你喜欢

Talk about the application of FIFO

21st day of written test mandatory training

Keras deep learning practice (15) -- realize Yolo target detection from scratch

Active vibration reduction system of hub motor and its vertical performance optimization

Common properties and traversal of trees and binary trees

正则表达式 \b \B 深入浅出理解单词边界的匹配

What is the experience of writing concurrent tool classes (semaphore, cyclicbarrier, countdownlatch) by yourself in line 30?

The local picture cannot be displayed after the uniapp H5 is packaged

08 reptile project

Machine learning notes - image homography estimation based on deep learning (homographynet)
随机推荐
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters
Regular expression \b \b understand word boundary matching in simple terms
4.合宙Air32F103_LCD
Developers share the first chapter of "Book Eating bar: deep learning and mindspire practice"
Using global data to realize data sharing in wechat applet
数据湖:开源数据湖方案DeltaLake、Hudi、Iceberg对比分析
CVE-2022-29464 WSO2文件上传漏洞
Qt ROS相关操作(运行终端指令、发布订阅自定义消息话题或服务、订阅图像并显示)
dynamixel舵机在ros下的workbnech使用
Shengsi YiDianTong | deep learning analysis of classical convolutional neural network
21st day of written test mandatory training
Emqx v4.4.5 Publishing: new exclusive subscriptions and mqtt 5.0 publishing attribute support
Batch visual target detection callout box -- Yolo format dataset
Arduino interrupt realizes rising edge detection and executes other functions
【云原生】快速了解Kubernetes
MySQL learning - MySQL software installation and environment configuration (Windows) details!
leetcode hot 100(刷題篇8)(232/88/451/offer10/offer22/344/)
DOM相关的方法概念
Worthington lysozyme technical description and literature reference
Read and understand the advantages of the LAAS scheme of elephant swap