1.移动端判断函数兼容关闭浏览器
_isMobile() {
let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag;
},
if (this._isMobile()) {
WeixinJSBridge.call('closeWindow');
} else if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
window.location.href="about:blank";
} else {
window.opener = null;
window.open("about:blank", "_self");
window.close();
}
2.环境判断
/**
* 是否微信内浏览器环境
*/
export const isWechatEnv = computed(() => {
const result = window.navigator.userAgent.match(/MicroMessenger/)
const isHttps = window.location.href.toLowerCase().indexOf('https://') == 0
return !!(result && result[0] && result[0] === 'MicroMessenger' && isHttps)
})
/**
* 是否微信小程序环境
*/
export const isWechatMpEnv = computed(() => !!(window.__wxjs_environment !== undefined && window.__wxjs_environment === 'miniprogram'))