问题
I am creating a webapp and the user could only have acces with the android webview? Can i detect android webview with javascript?
回答1:
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
回答2:
From 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.
回答3:
Why not add a secret param that you will set every time you need it?
来源:https://stackoverflow.com/questions/9942569/how-to-detect-with-javascript-if-browser-is-an-android-webview