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
How to Select All Checkboxes With Jquery
How to Use Jquery and Jquery Plugins With Primefaces
Prevent Body from Scrolling When a Modal Is Opened
Is There Any Cross-Browser JavaScript For Making Vh and Vw Units Work
How to Convert Unordered List into Nicely Styled ≪Select≫ Dropdown Using Jquery
Is $(Document).Ready() Also CSS Ready
Setting Vendor-Prefixed CSS Using JavaScript
How to Get the Background Color Code of an Element in Hex
Removing or Replacing a Stylesheet (A ≪Link≫) With JavaScript/Jquery
Animating Addclass/Removeclass With Jquery
Combine and Minify Multiple Css/Js Files
Get Computed Font Size For Dom Element in Js
How to Pause and Resume Css3 Animation Using JavaScript
How to Access CSS Generated Content With JavaScript
Compare Two Dates With JavaScript