Detect if user is using webview for android/iOS or a regular browser
Detecting browser for iOS devices is different from the Android one. For iOS devices you can do it by checking user agent using JavaScript:
var userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );
if( ios ) {
if ( safari ) {
//browser
} else if ( !safari ) {
//webview
};
} else {
//not iOS
};
For Android devices, you need to do it through server side coding to check for a request header.
PHP:
if ($_SERVER['HTTP_X_REQUESTED_WITH'] == "your.app.id") {
//webview
} else {
//browser
}
JSP:
if ("your.app.id".equals(req.getHeader("X-Requested-With")) ){
//webview
} else {
//browser
}
Ref:detect ipad/iphone webview via javascript
Note: This solution is PHP-based. HTTP
headers can be faked so this is not the nicest solution but you can have a start with this.
//For iOS
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile/') !== false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari/') == false) {
echo 'WebView';
} else{
echo 'Not WebView';
}
//For Android
if ($_SERVER['HTTP_X_REQUESTED_WITH'] == "com.company.app") {
echo 'WebView';
} else{
echo 'Not WebView';
}
For me this code worked:
var standalone = window.navigator.standalone,
userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test(userAgent),
ios = /iphone|ipod|ipad/.test(userAgent);
if (ios) {
if (!standalone && safari) {
// Safari
} else if (!standalone && !safari) {
// iOS webview
};
} else {
if (userAgent.includes('wv')) {
// Android webview
} else {
// Chrome
}
};