Home >Web Front-end >JS Tutorial >How to Detect iPad/iPhone WebViews Using JavaScript?
Detecting iPad/iPhone WebViews with JavaScript
Question: Can JavaScript detect if a website is running within iPad's Safari browser or an application's WebView?
Answer:
JavaScript provides an efficient way to determine the operating environment. Here's a comprehensive approach that leverages the combination of window.navigator.userAgent and window.navigator.standalone:
<code class="js">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 }</code>
Explanation:
This code evaluates the following scenarios:
The above is the detailed content of How to Detect iPad/iPhone WebViews Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!