当前位置:网站首页>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>边栏推荐
- c语言实现字符串逆序排列
- Using nodejs to operate MySQL
- Overall introduction of Ruiji takeout project
- 成立不到一年!MIT衍生量子计算公司完成900万美元融资
- 微信小程序使用canvas绘图,圆形头像,网络背景图,文字,虚线,直线
- How to realize dynamic route switching and route caching in vuejs
- Remember the first line segment tree (corresponding to Luogu 3372)
- 776. 字符串移位包含问题
- gprs网络指的是什么
- Sword finger offer II 063. replacement word (medium prefix tree string)
猜你喜欢

Paddlenlp text classification based on ernir3.0: take wos dataset as an example (hierarchical classification)

Mysql内置函数

Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)
Integrating database Ecology: using eventbridge to build CDC applications

Ngrok intranet penetration

What is time complexity
![[connect your mobile phone wirelessly] - debug your mobile device wirelessly via LAN](/img/7f/c49fd8c2cbe21585a080852833dcb4.png)
[connect your mobile phone wirelessly] - debug your mobile device wirelessly via LAN

Day3 classification management of Ruiji takeout project

Research cup element recognition multi label classification task based on ernie-3.0 cail2019 method

SQL injection less42 (post stack injection)
随机推荐
ATT&CK 威胁情报
Sword finger offer II 058. schedule (medium design segment tree treemap ordered set)
How to install WiFi correctly
Establishment of Ruiji takeout development environment
internet的基本服务中文件传输命令是哪个
【转载】token令牌在登录场景使用
ngx+sql环境离线安装日志(rpm安装)
CMD common commands
MySQL installation and configuration (super detailed, simple and practical)
2021 mathematical modeling group B code
php二维数组如何删除去除第一行元素
ssh免密登陆
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login
winServer运维技术栈
mysql create语句能不能用来建立表结构并追加新的记录
log4j漏洞 elk平台 处理方法 (logstah5.5.1)
[connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
基于Ernie-3.0 CAIL2019法研杯要素识别多标签分类任务