最近我遇到了一个非常讨厌的问题,所以我在我的webview中加载iframe(youtube视频)并检查WebView是否已完成加载,它适用于其他内容但不适用于iFrame,它显示页面加载完成的方式在iFrame完全加载之前。我尝试了SetWebChromeClient
和SetWebViewClient
- 在这两种情况下,都会在iFrame完成加载之前加载完成。
我有简单的WebView
webView.LoadDataWithBaseURL("https://.", IFRAME_HERE, "text/html", "UTF-8", null);
所以使用以下
设置webView.SetWebViewClient(new WebViewClientClass());
public override void OnPageStarted(WebView view, string url, Bitmap favicon)
{
base.OnPageStarted(view, url, favicon);
Log.Info("101029", "STARTED");
}
public override void OnPageFinished(WebView view, string url)
{
base.OnPageFinished(view, url);
Log.Info("101029", "FINISHED");
}
或使用以下
设置webView.SetWebChromeClient(new NewClient(ParentLayout, ContentLayout))
public override void OnProgressChanged(WebView view, int newProgress)
{
base.OnProgressChanged(view, newProgress);
if (newProgress == 100)
{
Log.Info("101029", "Finished");
}
else
{
Log.Info("101029", newProgress.ToString());
}
}
同样的事情发生,Webview显示加载完成,而iFrame仍在加载。如何解决iFrame的加载问题,以便在iFrame完成加载时准确获取? 任何的想法?干杯
编辑:
我还尝试了以下“`(仍然没有运气)
internal class WebViewClientClass : WebViewClient
{
bool loadingFinished = true;
bool redirect = false;
public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
{
if (!loadingFinished)
{
redirect = true;
}
loadingFinished = false;
Android.Net.Uri url = request.Url;
view.LoadUrl(url.ToString());
return true;
}
public override void OnPageStarted(WebView view, string url, Bitmap favicon)
{
base.OnPageStarted(view, url, favicon);
loadingFinished = false;
Log.Info("101029", "loading started");
}
public override void OnPageFinished(WebView view, string url)
{
if (!redirect)
{
loadingFinished = true;
}
if (loadingFinished && !redirect)
{
base.OnPageFinished(view, url);
Log.Info("101029", "loading finised");
}
else
{
redirect = false;
}
}
}