当前位置:网站首页>BOM (location object, navigation object)
BOM (location object, navigation object)
2022-07-28 22:37:00 【Green hedgerow bamboo maple】
1.location object
window Provides a location Property is used to get or set the name of the form URL, And can be used for parsing URL, Because this property returns an object , Therefore, this attribute is called location object
URL: Uniform resource locator , Standard resource addresses on the Internet , Every document in the history of the Internet has its own URL, It contains information about the location of the file and how the browser should handle it
URL General syntax format
protocol://host[:port]/path/[?query]#fragment
http://www.itcast.cn/index.html?name=andy&age=18#link| form | explain |
| protocol | Communication protocol , Commonly used http,ftp,matio etc. |
| host | host ( domain name )www.itheima.com |
| port | Port number , Optional , Omit is the default port of the use scheme , such as http Default 80 |
| path | route , There are dragons or more '/' Fu ha separated string , It is generally used to describe a directory or file address on the host |
| query | Parameters , In the form of key value pairs , adopt & separate |
| fragment | fragment ,# Buy your content later , Common in links , Anchor point |
1.1 location Object properties
| location Object properties | Return value |
| Gets or sets the entire URL |
| Back to the host ( domain name ),www.itcast.com |
| Return port number |
| Return path |
| Returns the parameter |
| Return fragment ,# Later , Common in links , Anchor point |
Jump to the page at the specified time
<body>
<button> Click on </button>
<div></div>
<script>
var btn = document.querySelector('button');
var div = document.querySelector('div');
btn.addEventListener('click', function () {
location.href = 'http://www.itcast.cn';
})
var timer = 5;
setInterval(function () {
if (timer == 0) {
location.href = 'http://www.itcast.cn';
} else {
div.innerHTML = ' You will be at ' + timer + ' Jump to home page ';
timer--;
}
}, 1000)
</script>
</body>1.2 location Object properties
| location Object methods | Return value |
| location.assign() | And href identical , You can jump to the page , You can go back to the page |
| location.replace() | Replace the current page , Because there's no history , You can't go back to the page |
| location.reload() | Little red heart loading page , Equivalent to letter page , Parameter is true, Means force refresh |
<body>
<button> Click on </button>
<script>
var btn = document.querySelector('button');
btn.addEventListener('click', function () {
// location.assign('http://www.itcast.cn');
location.replace('http://www.itcast.cn');
location.reload(true);
})
</script>
</body>2.navigation object
navigator Object contains information about the browser , He has many attributes , The most common is userAgent, This property can return the information sent by the client to the server user-agent The value of the head
The code used to judge the equipment
<script>
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|woSBrowser|BrowserNG|WebOS|Symbian|WindowsPhone)/i))) {
window.location.href = "";// mobile phone
} else {
window.location.href = "";// The computer
}
</script>3.histroy object
window Object provides us with a history object , Interact with browser history , This object contains the user ( In the browser window ) Visited URL
| history Object methods | effect |
| back() | You can step back |
| forward() | Forward |
| go( Parameters ) | Forward and backward function , Parameters 1 It means to advance one page , Parameters -1 Means to go back one page |
<body>
<a href="login.html"> Click to go to the login page </a>
<button> back off </button>
<script>
var btn = document.querySelector('button');
btn.addEventListener('click', function () {
history.back();
history.go(-1);
})
</script>
</body>边栏推荐
- [connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly
- 6K6w5LiA5qyh5pS75Ye75YiG5p6Q
- LeetCode刷题系列之-多数之和类型
- 75. Color classification (medium array double pointer sorting)
- Sword finger offer II 065. The shortest word code (medium dictionary tree string array)
- Netease Yunxin 2022q2 product supply station, come and get your product supply plan!
- Paddlenlp is based on ernir3.0 text classification. Take the crime prediction task of cail2018-small dataset as an example [multiple tags]
- Kali source solution software cannot be installed correctly
- 775. 倒排单词
- JS implementation generates a random key of specified length
猜你喜欢

SQL injection less38 (Stack Injection)

internet的基本服务中文件传输命令是哪个

Ngrok intranet penetration

Solve Jupiter: the term 'Jupiter' is not recognized as the name of a cmdlet, function, script file

MySQL installation and configuration (super detailed, simple and practical)

XXX port is already in use

JMeter installs third-party plug-ins plugins Manager

(翻译)图技术简明历史

LVS+KeepAlived高可用部署实战应用

Sword finger offer II 053. Medium order successor in binary search tree (medium binary search tree DFS)
随机推荐
ES6, deep copy, shallow copy
SSH password free login
How to install WiFi correctly
Changes in the history of oscilloscope development
【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
76. Minimum coverage substring (hard sliding window hash table string)
log4j漏洞 elk平台 处理方法 (logstah5.5.1)
There will be a black line on the border when the button in the wechat applet is clicked
What does GPRS network mean
JMeter installs third-party plug-ins plugins Manager
SQL injection less42 (post stack injection)
Static details of static members
Sword finger offer II 053. Medium order successor in binary search tree (medium binary search tree DFS)
Overall introduction of Ruiji takeout project
Leetcode integer exercises integer inversion
79. Word search (medium string array matrix backtracking)
Image is referred in multiple repositories
redis相关
【转载】token令牌在登录场景使用
使用webWorker执行后台任务