判斷當前頁面是否在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