简体   繁体   English

Android:Web 应用程序适用于 Chrome,但不适用于 Webview

[英]Android: Web App Works in Chrome, but not Webview

I am using ng-hide and ng-show in my web app to handle what gets displayed based on the user's login status.我在我的网络应用程序中使用ng-hideng-show来处理基于用户登录状态显示的内容。 This works completely fine if I go to the Chrome browser on my phone and run the site.如果我在手机上访问 Chrome 浏览器并运行该站点,这完全正常。

However, when I try to display it in a webview on my app or on the default phone non-Chrome browser, it does not work.但是,当我尝试在我的应用程序或默认手机非 Chrome 浏览器的 web 视图中显示它时,它不起作用。 None of the contents are hidden and the buttons which are binded to angularJS functions do not work.没有任何内容被隐藏,绑定到 angularJS 函数的按钮不起作用。 Note that I do have setJavaScriptEnabled(true) set.请注意,我确实设置了setJavaScriptEnabled(true)

When I looked this issue up, I noticed that some AngularJS features do not work on certain browsers (especially IE), thus it may be possible that AngularJS is incompatible with the default Webview.当我查看这个问题时,我注意到某些 AngularJS 功能在某些浏览器(尤其是 IE)上不起作用,因此可能是 AngularJS 与默认的 Webview 不兼容。 So is there a workaround or some way for me to make the webview emulate the Chrome browser?那么是否有解决方法或某种方法可以让 webview 模拟 Chrome 浏览器?

App on Chrome Browser: http://gyazo.com/8a8a56bdac1eb7e91753bc4745433a42 App on Webview: http://gyazo.com/a58de6192aa822af05a2885560e66f91应用在Chrome浏览器: http://gyazo.com/8a8a56bdac1eb7e91753bc4745433a42应用在网页视图: http://gyazo.com/a58de6192aa822af05a2885560e66f91

There are the following errors in the logcat, which I have investigated and make no sense since both variables have no issues in non-webview environments. logcat 中有以下错误,我已经调查过并且没有任何意义,因为这两个变量在非 webview 环境中都没有问题。

E/Web Console﹕ Uncaught SyntaxError: Unexpected identifier:103 E/Web 控制台: Uncaught SyntaxError: Unexpected identifier:103
E/Web Console﹕: Uncaught Error: No module: AuthApp:17 E/Web 控制台::未捕获的错误:无模块:AuthApp:17

The uncaught syntax error corresponds to the below, where results is the query results I am getting from Parse.未捕获的语法错误对应于以下内容,其中结果是我从 Parse 获得的查询结果。 Note that I have checked the contents of results in other browsers and it is in fact returning the results to my query.请注意,我已经在其他浏览器中检查了结果的内容,实际上它正在将结果返回给我的查询。

 for (var result of results){
...
}

try these settings on your webview. 在您的网页浏览中尝试这些设置。 i have had success in the past with these 我过去在这些方面取得了成功

mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setDomStorageEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());

you can add these lines, it will fix your issue您可以添加这些行,它将解决您的问题

when {
        Build.VERSION.SDK_INT >= 21 -> {
            binding.webView.settings.mixedContentMode = 0
            binding.webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
        }
        Build.VERSION.SDK_INT >= 19 -> {
            binding.webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
        }
        Build.VERSION.SDK_INT < 19 -> {
            binding.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
        }
    }

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

相关问题 html5视频无法在android webview中播放,但可以在(移动)chrome中使用 - html5 video does not play in android webview, but works in (mobile) chrome Android WebView不适用于默认浏览器,但适用于Chrome - Android WebView doesn't work with default browser, but works with Chrome 渐进式Web应用程序:离线缓存在Android上无效,适用于Chrome开发者工具 - Progressive Web App: offline cache does not work on Android, it works on Chrome dev Tools Android WebView-在浏览器中有效,但在WebView中无效 - Android WebView - Works in browser but not WebView Flutter web app in the Android webview calling method of injected Android object - Flutter web app in the Android webview calling method of injected Android object 使用Web抓取和后台WebView的Android登录应用 - Android Login app using web scraping with a background WebView 如何在 Android WebView 的 Web 应用程序端使用 backpress 事件? - How to consume backpress events in web app side in Android WebView? web 中的 firebase google 身份验证在 android 应用程序 webview 上不起作用 - firebase google authentication in web does not work on android app webview 如何在Chrome App中与WebView进行通信? - How to communicate with WebView in Chrome App? Google Chrome应用:Webview行为 - Google Chrome App: Webview behavior
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM