【问题标题】:How to detect is the webpage loaded successfully in Xamarin using WebView如何检测网页是否在 Xamarin 中使用 WebView 成功加载
【发布时间】:2021-03-21 12:25:08
【问题描述】:

我正在使用 WebView 在我的应用中加载网页。(使用 Xamarin 平台实现)

但是我想在网页加载失败时向用户弹出一条消息。(可能是由于没有互联网)

我该怎么做?

如何检测网页是否加载成功?

谢谢。

【问题讨论】:

  • 可以吗?

标签: xamarin webview xamarin.android xamarin.ios


【解决方案1】:

您可以使用 WebView Navigated 事件。

伴随Navigated 事件的WebNavigatedEventArgs 对象有一个名为Result 的属性,它使用WebNavigationResult 枚举成员描述导航结果。有效值为CancelFailureSuccessTimeout

<StackLayout>
        <WebView x:Name="webView" Source="https://www.google.com" WidthRequest="1000" Navigated="webView_Navigated" HeightRequest="1000"  />
</StackLayout>

private async void webView_Navigated(object sender, WebNavigatedEventArgs e)
    {
        if (e.Result == WebNavigationResult.Failure)
        {
            await DisplayAlert("Hi", "connect failure", "ok");
        }
        
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    相关资源
    最近更新 更多