判断当前页面是否在webview里面打开


原文链接:  https://blog.csdn.net/u010394015/article/details/80608701

 

function openInWebview () { var ua = navigator.userAgent.toLowerCase() if (ua.match(/MicroMessenger/i) == 'micromessenger') { // 微信浏览器判断
        return false } else if (ua.match(/QQ/i) == 'qq') { // QQ浏览器判断
        return false } else if (ua.match(/WeiBo/i) == "weibo") { return false } else { if (ua.match(/Android/i) != null) { return ua.match(/browser/i) == null } else if (ua.match(/iPhone/i) != null) { return ua.match(/safari/i) == null } else { return (ua.match(/macintosh/i) == null && ua.match(/windows/i) == null) } } } // 使用方式
if (openInWebview()) { // 在app内打开 // to do something
} else { // 其他地方 // 发起微信授权
}

 

备注:此判断在电脑端,使用手机模式预览,且选择安卓手机机型的时候,判断会有问题(会判断为是在app内打开)。但是在真机上是好的。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM