当前位置:网站首页>29. location object
29. location object
2022-06-11 19:56:00 【Suyuoa】
location yes window An attribute in an object , Used to get , Set up , Parse the form url(Unifrom Resource Locator, The Chinese name is unified resource locator , Commonly known as address ), Because this property returns an object , So we call this property location object
url It usually consists of the following parts
![]()

- query Also called query string
1 First time to know location
localtion Objects have the following common properties

Let's look at it in code


- The percent sign plus two numbers is the reason for the Chinese symbol
If you want to set location.href Just assign a value to this property

In this way, when you open this page with a browser, you will jump to Baidu

2 Automatically jump to the page after five seconds
Sometimes we visit a route that the website doesn't have at all , Under normal circumstances, it will report 404, We don't want to build one 404, Then we need to capture 404 Error of , Then redirect it (302) A customized page , We will do the function of this page next

I don't need the back-end framework , Just make a five second jump page , Jump to Baidu in five seconds

It turns on like this

Jump to Baidu in five seconds

Some websites remind you to register successfully , It can also 5s Jump to the home page , If you want to use the countdown effect, use setInterval(),setInterval() There is no need to clear the timer , The timer clears automatically after page Jump
3 Get between different addresses url Parameters
We have two pages , One is login.html, The other is index.html, stay login.html The user needs to fill in a string to index.html

Click to log in ,index Different results will be given according to the user name

login.html This is the code for

index.html This is the code for

There is a better way to parse the query string , Now let's look at the process of parameter passing , And it is impossible to input Chinese in this way , stay index.html There's a lot of garbled code in it
login.html And index.html Put it in the same directory

4 Common methods

4.1 location.assign()

Click the button and you will jump to Baidu

- Use location.assign() It is possible to retreat , to location.href Assignment can also be reversed
location.assign() And location.href Will record browsing history , So you can go back to the page

4.2 location.replace()

Click the button and you will jump to Baidu , Use location.replace() You can't go back

location.replace() Browsing history cannot be recorded , So you can't go back
4.3 location.reload
It is equivalent to refreshing the page

Without parameters, the default parameter is false, Equivalent to normal refresh , Clicking the button will refresh the current page , It is equivalent to clicking the refresh button

If you give parameters true, It is equivalent to a strong brush on the browser (ctrl+F5), A strong brush will erase some of the previously cached images and reload

Our current page is very simple, so there is no difference , If you make a static file image and display it in the web page , Then you change the still image , That makes a difference

边栏推荐
- APB2standard_ handshake_ Bridge design
- Anaconda安装、Jupyter Notebook默认启动路径修改及Nbextensions插件安装
- 浅聊对比学习(Contrastive Learning)第一弹
- 统一异常处理
- A Mechanics-Informed Artificial Neural Network Approach in Data-Driven Constitutive Modeling 学习
- 2022Redis7.0x版本持久化详细讲解
- [high precision] decimal integer addition
- Lecture 30 linear algebra Lecture 2 Matrix
- Flutter doctor 显示xcode没有安装的解决办法
- Unified exception handling
猜你喜欢

A brief talk on shutter button

基于飞桨搭建的多模态学习工具包PaddleMM

Linux环境安装mysql数据库详细教程(含卸载和密码重置过程)

Two minutes to show you the charging standard of the Sub Ledger System
![[Lao Wang's fallacy of brain science] Why do blind people](/img/7c/98f27bb55a1a3b74c0ed8fd7fd2cc5.jpg)
[Lao Wang's fallacy of brain science] Why do blind people "seem" to be more "sensitive" than normal people?

Hospital intelligent infusion management system source code hospital source code
【求助】請問如何讓微信公眾號文章在外部瀏覽器中打開後還能顯示下方的精選留言?

干货!基于序列超图神经网络的信息扩散预测

Flutter--Button浅谈

Hanging memory recursive dynamic programming (with example explanation POJ 1163)
随机推荐
Installation and performance test of Apache APIs IX on Amazon graviton3
Leetcode2027. 转换字符串的最少操作次数(可以,一次过)
MySQL——基本的Select语句
Summary 111111111111111111111
秀创意,赢显卡!MMPose姿态估计创意大赛震撼来袭
Hdu3527 (Hangdian) spy problem
Apache APISIX 在Amazon Graviton3 上的安装和性能测试
In 2021, the global revenue of minoxidil will be about 1035million US dollars, and it is expected to reach 1372.6 million US dollars in 2028
YOLOv3 Pytorch代码及原理分析(二):网络结构和 Loss 计算
09-MySQL锁
MySQL——事务
Image transformation torchvision Transforms notes
The principle that the picture of QQ Post Bar changes when it is opened
WR | effect of micro nano plastic pollution in Jufeng formation of West Lake University on microbial flora and nitrogen removal function of Constructed Wetland
unity里面使用opencv,qt建立plugin(一)
浅聊对比学习(Contrastive Learning)第一弹
这些考研专业容易混淆,搞错就白考啦!
AHB2APB_ Bridge design
Raki's notes on reading paper: learning fast, learning slow: a general continuous learning method
基于飞桨搭建的多模态学习工具包PaddleMM