我需要从Android WebView
或iOS UIWebView
或任何应用程序中检测使用情况。
检查移动设备的用户代理,如detecting-ios-android-operating-system或任何移动设备-
$(document).ready(function() {
if (/Mobi/.test(navigator.userAgent)) {
// mobile!
}
});
这是不够的,因为我想禁用一些按钮,并使用应用程序导航按钮,但如果用户在移动浏览器上,我想保留这些按钮。
发布于 2017-10-25 14:57:35
您可以使用以下方法来检测移动设备设备:
// 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
检测应用程序中的网页视图要困难得多,因为这些并不是真正区别于正常的浏览器视图。
从谷歌开发人员文档中,您可以查看Version/_X.X_
如果你试图区分WebView和Chrome for Android,你应该在WebView用户代理字符串中寻找Version/X.X字符串的存在。不要依赖特定的Chrome版本号(例如,30.0.0.0),因为版本号在每个版本中都会有所不同。
https://developer.chrome.com/multidevice/user-agent#webview_user_agent
然后这个帖子的答案给出了检测iOS的好信息
detect ipad/iphone webview via javascript
类似这样的评论: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);
https://stackoverflow.com/questions/46935579
复制相似问题