当前位置:网站首页>location对象,navigator对象,history对象学习
location对象,navigator对象,history对象学习
2022-08-02 08:08:00 【抱抱旋旋子】
location对象
一.什么是location对象
window对象给我们提供了一个location属性用于获取或设置窗体的URL,并且可以用于解析URL。因为这个属性返回的是一个对象,所以我们将这个属性也称为location对象。
二.URL的组成
统一资源定位符(Uniform Resource Locator, URL)是互联网上标准资源的地址。互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该怎么处理它。
URL 的一般语法格式为︰
三.location对象的属性

重点记住: href和search
location对象提供的search属性返回URL中的参数,通常用于在向服务器查询信息时传入一些查询条件,如页码,搜索关键字,排序方式等
四.五秒钟之后跳转页面
案例分析:
1.利用定时器做倒计时效果
2.时间到了,就跳转页面。使用location.href
五. 获取URL参数
1.第一个登录页面,里面有提交表单,action提交到index.html页面
2.第二个页面,可以使用第一个页面的参数,这样实现了一个数据不同页面之间的传递效果第二个
3.页面之所以可以使用第一个页面的数据,是利用了URL里面的location.search参数
4.在第二个页面中,需要把这个参数提取。
5.第一步去掉? 利用substr
6.第二步利用=号分割键和值split( '= )
效果图:


六.location常用方法

assign ()方法是比较常用的方式,使用location. assign()就可以立即打开一个新的浏览器位置,并生成一条新的历史记录。接收的参数为 URL地址。
reload ()方法的唯一参数,是一个布尔类型值,将其设置为 true时,它会绕过缓存,从服务器上重新下载该文档,类似于浏览器中的刷新页面”按钮。
replace()方法的作用就是使浏览器位置发生改变,并且禁止在浏览器历史记录中生成新的记录,它只接受一个要导航到的URL参数,而且在调用 replace()方法后,用户不能返回到前一个页面。

navigator对象
navigator对象包含有关浏览器的信息,它有很多属性,我们最常用的是userAgent,该属性可以返回由客户机发送服务器的user-agent头部的值。
下面前端代码可以判断用户那个终端打开页面,实现跳转
history对象
window对象给我们提供了一个history对象,与浏览器历史记录进行交互。该对象包含用户(在浏览器窗口中)访问过的URL。


history对象一般在实际开发中比较少用,但是会在一些OA办公系统中见到。
边栏推荐
- [ansible] playbook explains the execution steps in combination with the project
- R语言plotly可视化:使用plotly可视化模型预测真阳性率(True positive)TPR和假阳性率(False positive)FPR在不同阈值(threshold)下的曲线
- oracle的sql改成mysql版本
- @PostConstruct注解详解
- Ansible learning summary (11) - detailed explanation of forks and serial parameters of task parallel execution
- Biotin-EDA|CAS:111790-37-5| 乙二胺生物素
- redis高阶使用之Redisson分布式锁源码解析
- etcd implements large-scale service governance application combat
- houdini 求出曲线的法向 切线以及副法线
- QT web development - Notes - 3
猜你喜欢
![MFC最详细入门教程[转载]](/img/5d/655e75f6b8a547fefe0137a9b11536.png)
MFC最详细入门教程[转载]

血气方刚的年轻小伙竟去做家政小哥,是怎样成功逆袭转行的
![Three types of [OC learning notes] Block](/img/40/edf59e6e68891ea7c9ab0481fe7bfc.png)
Three types of [OC learning notes] Block

cas: 139504-50-0 Maytansine DM1|Mertansine|

工程师如何对待开源 --- 一个老工程师的肺腑之言

C语言基础_共用体

EPSANet: An Efficient Pyramid Split Attention Block on Convolutional Neural Network

etcd实现大规模服务治理应用实战

Business Intelligence Platform BI Business Intelligence Analysis Platform How to Choose the Right Business Intelligence Platform BI

PostgreSQL学习总结(11)—— PostgreSQL 常用的高可用集群方案
随机推荐
血气方刚的年轻小伙竟去做家政小哥,是怎样成功逆袭转行的
商业智能平台BI 商业智能分析平台 如何选择合适的商业智能平台BI
【电子电路】长按键拉低电平,适用在有休眠机制的MCU但是没有看门狗,一个按键多个功能场景下使用
CASA模型、CENTURY模型应用与案例分析
Flink 程序剖析
The crawler video crawl tools you get
爬虫——爬虫初识、requests模块
R language plotly visualization: plotly visualizes the scatter plot of the actual value of the regression model and the predicted value of the regression, analyzes the prediction performance of the re
OneNote Tutorial, How to Create More Spaces in OneNote?
类和对象【下】
C语言_指针
【开源项目】X-TRACK源码分析
IO process thread -> process -> day4
etcd实现大规模服务治理应用实战
Biotinyl Cystamine | CAS: 128915-82-2 | biotin cysteamine
力扣:第 304 场周赛
Business Intelligence Platform BI Business Intelligence Analysis Platform How to Choose the Right Business Intelligence Platform BI
cas: 139504-50-0 Maytansine DM1|Mertansine|
R language plotly visualization: use the plotly visualization model to predict the true positive rate (True positive) TPR and false positive rate (False positive) FPR curve under different thresholds
Redisson distributed lock source code analysis for high-level use of redis