| 1 | /** |
| 2 | * 浏览器环境判断工具 |
| 3 | */ |
| 4 | |
| 5 | function getBrowserUserAgent() { |
| 6 | if (typeof window === 'undefined') |
| 7 | return '' |
| 8 | |
| 9 | return window.navigator.userAgent.toLowerCase() |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * 判断当前页面是否运行在微信内置浏览器或 WebView 中。 |
| 14 | */ |
| 15 | export function isWechatWebView() { |
| 16 | return getBrowserUserAgent().includes('micromessenger') |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * 判断当前页面是否运行在支付宝内置浏览器或 WebView 中。 |
| 21 | */ |
| 22 | export function isAlipayWebView() { |
| 23 | return getBrowserUserAgent().includes('alipayclient') |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * 判断当前页面是否运行在需要提示切换系统浏览器的 App 内置浏览器中。 |
| 28 | */ |
| 29 | export function isBrowserOpenGuideWebView() { |
| 30 | return isWechatWebView() || isAlipayWebView() |
| 31 | } |
| 32 |