30 lines
785 B
JavaScript
30 lines
785 B
JavaScript
export default class Client {
|
|
|
|
/**
|
|
* 跳转系统浏览器
|
|
* @description 原生需提供方法 openPhoneBrowser
|
|
* @param {String} url 链接
|
|
*/
|
|
static openPhoneBrowser(url) {
|
|
if (!url) {
|
|
return false
|
|
}
|
|
try {
|
|
const u = navigator.userAgent
|
|
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1
|
|
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
|
|
if (isAndroid && window.android.openPhoneBrowser) {
|
|
window.android.openPhoneBrowser(url)
|
|
return true
|
|
} else if (isiOS && window.webkit && window.webkit.messageHandlers &&
|
|
window.webkit.messageHandlers.openPhoneBrowser) {
|
|
window.webkit.messageHandlers.openPhoneBrowser.openPhoneBrowser(url)
|
|
return true
|
|
}
|
|
} catch (e) {
|
|
return false
|
|
}
|
|
return false
|
|
}
|
|
}
|