【发布时间】:2016-10-02 03:45:31
【问题描述】:
如何检测用户是否正在使用 webview for android 或 iOS 浏览页面?
在 stackoverflow 上发布了各种解决方案,但我们还没有针对这两种操作系统的防弹解决方案。
目的是一个if语句,例如:
if (android_webview) {
jQuery().text('Welcome webview android user');
} else if (ios_webview) {
jQuery().text('Welcome webview iOS user');
} else if (ios_without_webview) {
// iOS user who's running safari, chrome, firefox etc
jQuery().text('install our iOS app!');
} else if (android_without_webview) {
// android user who's running safari, chrome, firefox etc
jQuery().text('install our android app!');
}
到目前为止我已经尝试过什么
检测 iOS 网页视图 (source):
if (navigator.platform.substr(0,2) === 'iP'){
// iOS (iPhone, iPod, iPad)
ios_without_webview = true;
if (window.indexedDB) {
// WKWebView
ios_without_webview = false;
ios_webview = true;
}
}
检测android webview,我们有很多解决方案,例如this 和this。我不确定什么是合适的方法,因为每个解决方案似乎都有问题。
【问题讨论】:
-
应用中是否使用了WebView?
-
是的,如您所见。 :)
-
您是否考虑过在 WebView 中使用自定义 User-Agent 标头来区分? @Henrik
-
@David8 是的,请查看用户代理方法的链接答案及其问题。
-
Google docs for find webview using 'wv' check developer.chrome.com/multidevice/user-agent#webview_user_agent
标签: javascript jquery