简体   繁体   English

如果浏览器是android webview,如何使用javascript检测?

[英]how to detect with javascript if browser is an android webview?

I am creating a webapp and the user could only have acces with the android webview?我正在创建一个 web 应用程序,而用户只能访问 android webview? Can i detect android webview with javascript?我可以用javascript检测android webview吗?

From http://developer.android.com/guide/webapps/webview.html#EnablingJavaScript来自http://developer.android.com/guide/webapps/webview.html#EnablingJavaScript

For example, if you're developing a web application that's designed specifically for the WebView in your Android application, then you can define a custom user agent string with setUserAgentString(), then query the custom user agent in your web page to verify that the client requesting your web page is actually your Android application.例如,如果您正在开发专为 Android 应用程序中的 WebView 设计的 Web 应用程序,那么您可以使用 setUserAgentString() 定义自定义用户代理字符串,然后在您的网页中查询自定义用户代理以验证请求您的网页的客户端实际上是您的 Android 应用程序。

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
  // Do something!
  // Redirect to Android-site?
  window.location = 'http://android.davidwalsh.name';
}

Source : http://davidwalsh.name/detect-android来源: http : //davidwalsh.name/detect-android

为什么不添加一个每次需要时都会设置的秘密参数?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM