我如何加载下一个web视图之前明确previous的WebView内容? [英] How do I clear previous WebView's content before loading the next WebView?

查看:188
本文介绍了我如何加载下一个web视图之前明确previous的WebView内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的方案最初是我加载的WebView,后来我加载相同的WebView有不同的URL。

My scenario is initially I am loading a WebView and later on I am loading the same WebView with a different URL.

我的问题是,每当我加载下一个URL,我可以看到previously加载URL的内容,然后我当前加载URL的内容被显示出来。

My problem is whenever I am loading the next URL I can see the previously loaded URL contents and then my currently loaded URL contents gets displayed.

我想清楚了,每当我加载了不同的URL的内容。

I want to clear the contents whenever I am loading the different URL.

说,

if (pos == 0) {
    mweb.clearCache(true);
    mweb.clearHistory();
    mweb.loadUrl("http://stackoverflow.com/");
}
else if (pos == 1) {
    mweb.clearCache(true);
    mweb.clearHistory();
    mweb.loadUrl("http://android.stackexchange.com/");
}

两个 clearCache() clearHistory()对我来说是行不通的。

Both clearCache() and clearHistory() does not work for me.

推荐答案

使用 mweb.clearView(); 之前加载新的URL

use mweb.clearView(); before loading the new URL.

编辑:

ClearView的()是pcated在API层面18. WebView.loadUrl(有关:空白)德$ P $ 可靠复位视图状态和释放网页资源(包括所有正在运行的JavaScript)。

clearView() was deprecated in API level 18. Use WebView.loadUrl("about:blank") to reliably reset the view state and release page resources (including any running JavaScript).

来解决@Liang提出的问题:

to solve the issue raised by @Liang:

要具有一致的后退导航,可以覆盖onPageFinished,和里面检查网址是否包含有关:空白与否。如果是的话,请使用webview.goBack()

To have a consistent back navigation, you can override "onPageFinished", and inside it check whether the url contains "about:blank" or not. if yes, use "webview.goBack()"

这篇关于我如何加载下一个web视图之前明确previous的WebView内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆