当前位置:网站首页>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>边栏推荐
- 软考网络工程师
- Sword finger offer II 065. The shortest word code (medium dictionary tree string array)
- Winserver operation and maintenance technology stack
- Using nodejs to operate MySQL
- ssh免密登陆
- imx6q gpio复用
- 776. 字符串移位包含问题
- Ruiji takeout project - development of business development function Day2
- There will be a black line on the border when the button in the wechat applet is clicked
- ATT&CK初步了解
猜你喜欢

Mysql内置函数
How do we do full link grayscale on the database?

静态成员static详解

Lvs+keepalived high availability deployment practical application

Jmeter 安装第三方插件 Plugins Manager

Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)

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

79. Word search (medium string array matrix backtracking)

基于Ernie-3.0 CAIL2019法研杯要素识别多标签分类任务

【转载】token令牌在登录场景使用
随机推荐
When can I sign up for the 2022 class I constructor examination?
Ruiji takeout - background login function development
What is time complexity
Ngx+sql environment offline installation log (RPM installation)
Use REM to make the font size adaptive to the screen
ES6, deep copy, shallow copy
Ecmasript 5/6 notes
【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
Can the MySQL create statement be used to create a table structure and append new records
Is mov format a still image file format
[binary tree] pseudo palindrome path in binary tree
npm ERR code ETIMEDOUT npm ERR syscall connect npm ERR errno ETIMEDOUT npm ERR network reques...
纪念一下第一次写的线段树了喽(对应洛谷3372)
Jmeter 安装第三方插件 Plugins Manager
Sword finger offer II 057. the difference between the value and the subscript is within the given range (medium array bucket sort sliding window TreeSet)
Container configuration starts redis cluster single machine 6 nodes 3 Master 3 slave
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
CMD common commands
Changes in the history of oscilloscope development
[get mobile information] - get mobile information through ADB command