Commit 23aae09f3e28aa4688efac4c188a7b779c181e0f
1 parent
bdc1051f
js判断从带#号的链接拿值
Showing
1 changed file
with
7 additions
and
4 deletions
static/js/cnLive_openinstall.js
| ... | ... | @@ -2,10 +2,13 @@ |
| 2 | 2 | /*web页面向app传递的json数据(json string/js Object),应用被拉起或是首次安装时,通过相应的android/ios api可以获取此数据*/ |
| 3 | 3 | //获取url地址里的参数 |
| 4 | 4 | function getUrlParam(name) { |
| 5 | - var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); | |
| 6 | - var r = window.location.hash.substr(1).match(reg); | |
| 7 | - if (r != null) return r[2]; | |
| 8 | - return ""; | |
| 5 | + let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); | |
| 6 | + if (window.location.hash.indexOf("?") < 0) { | |
| 7 | + return null; | |
| 8 | + } | |
| 9 | + let r = window.location.hash.split("?")[1].match(reg); | |
| 10 | + if (r != null) return decodeURIComponent(r[2]); | |
| 11 | + return null; | |
| 9 | 12 | } |
| 10 | 13 | //获取url地址里的参数转成json格式 |
| 11 | 14 | function parseQueryString() { | ... | ... |