当前位置:网站首页>[JS] get the search parameters of URL in hash mode
[JS] get the search parameters of URL in hash mode
2022-07-02 19:51:00 【A meteor unwilling to fall】
List of articles
- Function encapsulation :
function getHashSearchParam(key) {
const url = location.href
// obtain hash value , It doesn't contain '#' Number
const hash = url.substring(url.indexOf("#") + 1)
// lookup '?' Index of number
const searchIndex = hash.indexOf("?")
// '?' Followed by the index parameter , If found, then +1, Remove '?' Number
const search = searchIndex !== -1 ? hash.substring(searchIndex + 1) : ""
// Mention the search parameter string URLSearchParams Into object form
const usp = new URLSearchParams(search)
// adopt URLSearchParams Self contained get Method , The value corresponding to the query key
return usp.get(key)
}
- Use cases :
// Suppose the current page url by
https://www.test.com/#/aa/bb?project_id=666
const project_id = getHashSearchParam("project_id")
console.log(project_id) // '666'
边栏推荐
- SQLite 3.39.0 release supports right external connection and all external connection
- Detailed explanation of VBScript (I)
- Kt148a voice chip IC user end self replacement voice method, upper computer
- Is there any security guarantee for the ranking of stock and securities companies
- SQLite 3.39.0 发布,支持右外连接和全外连接
- pxe装机「建议收藏」
- Function high order curry realization
- Py之interpret:interpret的简介、安装、案例应用之详细攻略
- AcWing 1126. 最小花费 题解(最短路—dijkstra)
- AcWing 341. 最优贸易 题解 (最短路、dp)
猜你喜欢
数据湖(十二):Spark3.1.2与Iceberg0.12.1整合
【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
Kt148a voice chip IC user end self replacement voice method, upper computer
【Hot100】21. 合并两个有序链表
Self-Improvement! Daliangshan boys all award Zhibo! Thank you for your paper
Bubble sort array
Istio部署:快速上手微服务,
字典
良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
随机推荐
自動生成VGG圖像注釋文件
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
AcWing 1137. Select the best line solution (the shortest circuit)
Automatically generate VGg image annotation file
Py's interpret: a detailed introduction to interpret, installation, and case application
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
JS如何取整数
Detailed explanation of VBScript (I)
【Hot100】23. 合并K个升序链表
Correspondence between pytoch version, CUDA version and graphics card driver version
450 Shenxin Mianjing 1
Implementation of 453 ATOI function
c语言里怎么设立优先级,细说C语言优先级
What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development
[NLP] a detailed generative text Abstract classic paper pointer generator
Istio deployment: quickly start microservices,
PXE installation "recommended collection"
How to avoid duplicate data in gaobingfa?