当前位置:网站首页>[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'
边栏推荐
- Automatic reading of simple books
- Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
- AcWing 342. Road and route problem solving (shortest path, topological sorting)
- 多态的理解以及作用
- 【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
- How to avoid duplicate data in gaobingfa?
- Yes, that's it!
- Correspondence between pytoch version, CUDA version and graphics card driver version
- AcWing 1131. 拯救大兵瑞恩 题解(最短路)
- rxjs Observable 自定义 Operator 的开发技巧
猜你喜欢
高并发下如何避免产生重复数据?
定了,就是它!
Py's interpret: a detailed introduction to interpret, installation, and case application
勵志!大凉山小夥全獎直博!論文致謝看哭網友
编写完10万行代码,我发了篇长文吐槽Rust
有时候只查询一行语句,执行也慢
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
Set up sentinel mode. Reids and redis leave the sentinel cluster from the node
AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)
随机推荐
【每日一题】241. 为运算表达式设计优先级
Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
AcWing 1129. 热浪 题解(最短路—spfa)
What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development
Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
NMF-matlab
JS如何取整数
AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
NMF-matlab
AcWing 383. 观光 题解(最短路)
Use cheat engine to modify money, life and stars in Kingdom rush
AcWing 1126. Minimum cost solution (shortest path Dijkstra)
c语言链表--待补充
CRM客户关系管理系统
Refactoring: improving the design of existing code (Part 2)
AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)
Istio部署:快速上手微服务,
【Hot100】21. 合并两个有序链表
Chapter 7 - class foundation
Postman下载安装