0

I need to detect a usage from Android WebView or iOS UIWebView or any in app usage.

Checking the user agent for mobile like detecting-ios-android-operating-system or any mobile like -

$(document).ready(function() {
    if (/Mobi/.test(navigator.userAgent)) {
        // mobile!
    }
});

Is not enough beacuse I want to disable some button and use the application navigation buttons but if the user is on mobile browser I want to keep the buttons.

Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

1 Answers1

0

You can use the following to detect mobile devices devices:

// detect browser
    var android = navigator.userAgent.match(/Android/i) != null;    // Check if using Android
    var iPad = navigator.userAgent.match(/iPad/i) != null;          // Check if using an iPad
    var iPhone = navigator.userAgent.match(/iPhone/i) != null;      // Check if using an iPhone

Detecting Webviews inside apps is much harder as those are not really distinguished from normal browser views.

From Google Dev docs you can check for Version/_X.X_:

If you’re attempting to differentiate between the WebView and Chrome for Android, you should look for the presence of the Version/X.X string in the WebView user-agent string. Don’t rely on the specific Chrome version number (for example, 30.0.0.0) as the version numbers changes with each release.

https://developer.chrome.com/multidevice/user-agent#webview_user_agent

And then this posts answer gives good info on detecting for iOS

detect ipad/iphone webview via javascript

Something like this comment: https://stackoverflow.com/a/10170885/5234751

var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
var is_safari_or_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);
Dieskim
  • 600
  • 3
  • 12