Android WebView不打开CSS/JavaScript服务器端PHP

发布于 2025-01-29 11:50:44 字数 1031 浏览 2 评论 0 原文

我正在使用Xamarin Android,但是如果您提供Java代码也很好。 我注意到当我打开某些URL页面时,我会收到一个空白页,但是如果我在测试设备上打开了Google Chrome中的thesame网页,它将打开NOTEY。

我没有运气就完成了以下操作:

WebView web_view = view.FindViewById<WebView>(Resource.Id.webView1);
            web_view.SetWebChromeClient(new WebChromeClient());
            web_view.Settings.LoadWithOverviewMode = true;
            web_view.Settings.JavaScriptEnabled = true;
            web_view.Settings.CacheMode = CacheModes.Normal;
            web_view.Settings.UserAgentString = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
            web_view.Settings.DomStorageEnabled = true;
            web_view.Settings.DatabaseEnabled = true;
            web_view.Settings.UseWideViewPort = true;
            web_view.Settings.SetPluginState(WebSettings.PluginState.On);
            web_view.LoadUrl("url_here");

我还添加了“ Android:useClearTextTraffic =“ true”“我的Android应用程序标签”。

我还添加了Internet许可,并且使用了HTTPS,但我得到了一个空白页。

i am using xamarin android but if you provide java code is also good.
I noticed when i open certain url pages, i get a blank page but if i open thesame webpage in google chrome on my test device it opens nicey.

I have done the following with no luck:

WebView web_view = view.FindViewById<WebView>(Resource.Id.webView1);
            web_view.SetWebChromeClient(new WebChromeClient());
            web_view.Settings.LoadWithOverviewMode = true;
            web_view.Settings.JavaScriptEnabled = true;
            web_view.Settings.CacheMode = CacheModes.Normal;
            web_view.Settings.UserAgentString = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
            web_view.Settings.DomStorageEnabled = true;
            web_view.Settings.DatabaseEnabled = true;
            web_view.Settings.UseWideViewPort = true;
            web_view.Settings.SetPluginState(WebSettings.PluginState.On);
            web_view.LoadUrl("url_here");

I have also added "android:usesCleartextTraffic="true"" in my android application tag manifest.

Offcourse i also added the internet permission and i using https but i get a blank page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慵挽 2025-02-05 11:50:44

我已经解决了这个问题...
首先创建一个WebViewClient类:

public class MyBabyclient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
        {
            view.LoadUrl(request.Url.ToString());
            return false;
        }
    }

然后将其分配到您的WebView:web_view.setwebviewclient(new mybabyclient());

更多信息可以在此处看到:

I have fixed this issue...
First create a webviewclient class :

public class MyBabyclient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
        {
            view.LoadUrl(request.Url.ToString());
            return false;
        }
    }

Then assign it to your webview : web_view.SetWebViewClient(new MyBabyclient());

More info can be seen here : https://learn.microsoft.com/en-us/xamarin/android/user-interface/controls/web-view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文