| 11 | } |
| 12 | |
| 13 | export function getUrlParam (name: string) { |
| 14 | let {search} = window.location; |
| 15 | const {hash} = window.location; |
| 16 | // # 在 ? 之前,即 http://localhost/#file?key=value,会导致 search 为空。 |
| 17 | if (search === '' && hash !== '') { |
| 18 | // 为 search 补上前缀'?',以便后面的逻辑处理不变。 |
| 19 | search = `?${hash.split('?')[1]}`; |
| 20 | } |
| 21 | if (search !== '' && search !== undefined) { |
| 22 | const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); |
| 23 | const r = search.substr(1).match(reg); |
| 24 | if (r != null) { |
| 25 | return unescape(r[2]); |
| 26 | } |
| 27 | } |
| 28 | return ''; |
| 29 | } |
| 30 | |
| 31 | export function onPageShowHide ( |
| 32 | onshow: ()=>void, |