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

核能气质少年 提交于 2019-12-23 10:09:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!