当前位置:网站首页>URL related knowledge points
URL related knowledge points
2022-07-28 13:56:00 【Good [email protected]】
Catalog
BOM_location
At present url For example
https://element.eleme.cn/?id=111&name=222#/zh-CN/component/button
effect
obtain At present url Related information !
attribute
The following attributes are in addition to origin attribute ( read-only ) All are Can read but write attribute !
// Get the complete url https://element.eleme.cn/?id=111&name=222#/zh-CN/component/button
location.href
// Get current url Domain name of ( Standard form ) https://element.eleme.cn
location.origin
// Get current url The agreement name of https:
location.protocol(*/*ˈprəʊtəkɒl*/*)
// Get current url Domain name of // element.eleme.cn
location.hostname
// Get current url Port number ''
location.port
// Get current url Parameters carried , With “?” start ?id=111&name=222
location.search
// Get current url Of hash value , With “#” start #/zh-CN/component/button
location.hash
Method
// Reload
location.reload()
// Replace the current path - Open a new page
location.replace( new url)
// Get current full url
location.toString() // pre location.href Function the same ( But it's read-only , Do not modify url)
URL Constructors
effect
Create and return Appoint url object
attribute
[1] contain location Object properties ;
const url = new URL('https://element.eleme.cn/?id=111&name=222#/zh-CN/component/button')
console.log(url) // URL object
console.log(url.href) // https://element.eleme.cn/?id=111&name=222#/zh-CN/component/button
console.log(url.origin) // https://element.eleme.cn
console.log(url.protocol)// https:
console.log(url.hostname) // element.eleme.cn
console.log(url.port) //
console.log(url.search)// ?id=111&name=222
console.log(url.hash) // #/zh-CN/component/button
[2]searchParams attribute
- Read-only property
- The return value is URLSearchParams object
- Properties are not displayed directly
- You can't get
searchparams object
Cannot get its properties directly
const url = new URL('https://element.eleme.cn/?id=111&id=222&name=222#/zh-CN/component/button') const { searchParams} = url // URLSearchParams {}
You can get
(1)get Method : The first value of the search parameter
console.log(' result ', searchParams.get('id')) // 111
(2)getAll Method : Gets all values of the specified search parameter , The return is an array
console.log(searchParams.getAll('id')) //['111','222'] console.log(searchParams.getAll('b')) // []
(3)has Method : Determine whether this search parameter exists
console.log(searchParams.has('id')) //true console.log(searchParams.has('b')) // false
Method
URL.createObjectURL
grammar
URL.createObjectURL(object)object The parameter can be a File object or Blob object ; Not a remote link !
example
[1] obtain url Portability parameter
(1) adopt location Object get parameters
const { search } = location const paramsArr = search.split('?')[1].split('&') const id = paramsArr[0].split('=')[1] // 111 const name = paramsArr[1].split('=')[1] // 222
(2) By creating a URl Object get parameters
const { searchParams } = new URL(window.location) const id = searchParams.get('id') // 111 const name = searchParams.get('name') // 222
版权声明
本文为[Good [email protected]@@]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207281250142394.html
边栏推荐
- 正则表达式
- 7.依赖注入
- .net for subtraction, intersection and union of complex type sets
- 多线程与高并发(三)—— 源码解析 AQS 原理
- [C language] the difference between structure pointer and structure variable as formal parameters
- Debezium series: major changes and new features of 2.0.0.beta1
- Deploy application delivery services in kubernetes (Part 1)
- DOJP1520星门跳跃题解
- Can second uncle cure young people's spiritual internal friction?
- To build agile teams, these methods are indispensable
猜你喜欢

word打字时后面的字会消失是什么原因?如何解决?

DXF reading and writing: align the calculation of the position of the dimension text in the middle and above

strcmp、strstr、memcpy、memmove的实现

Strict mode -- let and const -- arrow function -- Deconstruction assignment -- string template symbol -- set and map -- generator function

不用Swagger,那我用啥?

性能超群!牛津&上海AI Lab&港大&商汤&清华强强联手,提出用于引用图像分割的语言感知视觉Transformer!代码已开源...

Humiliation, resistance, reversal, 30 years, China should win Microsoft once

Cool operation preheating! Code to achieve small planet effect
JWT 登录认证 + Token 自动续期方案,写得太好了!

How to play a data mining game entry Edition
随机推荐
30天刷题训练(一)
30天刷题计划(四)
R语言可视化散点图、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(使用参数xlim和ylim将标签添加到可视化图像的特定区域、指定标签线段并添加箭头)
掌握常见的几种排序-选择排序
面经整理,助力秋招,祝你称为offer收割机
Force buckle 2354. Number of high-quality pairs
Leetcode depth first and breadth first traversal
Better and more modern terminal tools than xshell!
你真的了解esModule吗
R语言ggplot2可视化:可视化散点图并为散点图中的数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点标签互相重叠(自定义指定字体类型font family)
R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses conflict function to give 95% confidence interval of regressi
30 day question brushing plan (III)
.net for subtraction, intersection and union of complex type sets
在 Kubernetes 中部署应用交付服务(第 1 部分)
比XShell更好用、更现代的终端工具!
最强分布式锁工具:Redisson
Li Kou sword finger offer 51. reverse order pairs in the array
Cool operation preheating! Code to achieve small planet effect
SQL每日一练(牛客新题库)——第4天:高级操作符
图的遍历(BFS&&DFS基础)