Detect Ipad/Iphone Webview Via JavaScript

detect ipad/iphone webview via javascript

This uses a combination of window.navigator.userAgent and window.navigator.standalone. It can distinguish between all four states relating to an iOS web app: safari (browser), standalone (fullscreen), uiwebview, and not iOS.

Demo: http://jsfiddle.net/ThinkingStiff/6qrbn/

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 ) {
//browser
} else if ( standalone && !safari ) {
//standalone
} else if ( !standalone && !safari ) {
//uiwebview
};
} else {
//not iOS
};

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

Detecting whether webview or external browser in javascript

Take a look at the user-agent, there should be differences - notably, non-webview mobile devices explicitly mention Safari. The following question has some sample code that you can use to detect the difference.

detect ipad/iphone webview via javascript

Detect if page is loaded inside WKWebView in JavaScript

You can check for the existence of window.webkit.messageHandlers which WKWebKit uses to receive messages from JavaScript. If it exists, you're inside a WKWebView.

That combined with a simple user agent check should do the trick:

var iOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false);
var isWKWebView = false;
if (window.webkit && window.webkit.messageHandlers) {
isWKWebView = true;
}

How do I detect a ipad/iphone webview in user agent using regex in Python?

Use re.search() for this in Python.

userAgent = "YOUR_UA"
pattern = '(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)'
if(re.search(pattern, userAgent)):
print "true"


Related Topics



Leave a reply



Submit