当前位置:网站首页>[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'
边栏推荐
- 攻防世界pwn题:Recho
- c语言里怎么设立优先级,细说C语言优先级
- 自动生成VGG图像注释文件
- Detailed tutorial on installing stand-alone redis
- Workplace four quadrant rule: time management four quadrant and workplace communication four quadrant "suggestions collection"
- AcWing 903. Expensive bride price solution (the shortest path - building map, Dijkstra)
- 在消费互联网时代,诞生了为数不多的头部平台的话
- Istio1.12:安装和快速入门
- GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
- Notes on hardware design of kt148a voice chip IC
猜你喜欢
Refactoring: improving the design of existing code (Part 2)
Automatically generate VGg image annotation file
rxjs Observable 自定义 Operator 的开发技巧
GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
自動生成VGG圖像注釋文件
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
Yes, that's it!
KT148A语音芯片ic的开发常见问题以及描述
CRM客户关系管理系统
Génération automatique de fichiers d'annotation d'images vgg
随机推荐
GCC: Graph Contrastive Coding for Graph Neural NetworkPre-Training
Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem
KT148A语音芯片使用说明、硬件、以及协议、以及常见问题,和参考代码
Chapter 7 - class foundation
JASMINER X4 1U深度拆解,揭开高效省电背后的秘密
职场四象限法则:时间管理四象限与职场沟通四象限「建议收藏」
Refactoring: improving the design of existing code (Part 2)
How to avoid duplicate data in gaobingfa?
中缀表达式转换为后缀表达式(C语言代码+详解)
NMF-matlab
自动化制作视频
Codeforces Round #802 (Div. 2) 纯补题
CheckListBox control usage summary
自动生成VGG图像注释文件
AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
LeetCode 0871. Minimum refueling times - similar to poj2431 jungle adventure
[ERP software] what are the dangers of the secondary development of ERP system?
Conscience summary! Jupyter notebook from Xiaobai to master, the nanny tutorial is coming!
Start practicing calligraphy
AcWing 1137. Select the best line solution (the shortest circuit)