How to detect if the user is browsing the page using webview for android or iOS?
There are various solutions posted all over stackoverflow, but we don't have a bulletproof solution yet for both OS.
The aim is an if statement, example:
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!');
}
What I've tried so far
Detect iOS webview (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;
}
}
Detect android webview, we have a number of solutions like this and this. I'm not sure what's the appropriate way to go because every solution seems to have a problem.