更改Android Webview内容(哈希),而无需重新加载url [英] Change Android webview content (hash) without reloading the url
问题描述
我有2个Webview:Webview1和Webview2(比如说).用户到达Webview1(加载URL).现在,当用户单击Webview2时,我需要加载一个网址,如www.abcd.com#Page1.现在,当用户遍历Webview1中的第二个页面时,我需要在Webview2中加载www.abcd.com#Page2.同样,当用户浏览Webview1中的页面时,我需要相应地更改Webview2中的内容.
I have 2 webviews : Webview1 and Webview2 (say). The user arrives at Webview1 (an url loads). Now when the user clicks on Webview2, I need to load a url like www.abcd.com#Page1. Now when the user traverses to the second page in Webview1, I need to load www.abcd.com#Page2 in Webview2. Likewise, when the user traverses through pages in Webview1, I need to change the content in Webview2 accordingly.
但是,如果我每次都使用Webview2.loadurl()
,则需要花费一些时间来加载.相反,我只想更改内容而不重新加载它.
But if I use Webview2.loadurl()
everytime, it takes time to load. Instead I want to just change the content without reloading it.
注意:我从Webview1获得了值#Page1,#Page2等,因此不必理会.请让我知道如何在不每次都在Android Webview中重新加载新网址的情况下实现此目标.
Note : I get the values #Page1, #Page2 etc from Webview1, so don't bother about it. Please let me know how to achieve this without reloading the new url everytime in Android webview.
推荐答案
我知道了:
最初使用URL加载Web视图(例如www.abcd.com#Page1
).现在,每当您要更新www.abcd.com#Page2
之类的网址(哈希值从Page1更改为Page2)时,只需执行以下操作:
Load the webview initially with the url (say www.abcd.com#Page1
). Now whenever you want to update the url like www.abcd.com#Page2
(Hash value changes from Page1 to Page2), just do the following :
webView.evaluateJavascript("location.hash=\"" + url + "\";", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
if(Debugging.Enabled) Log.d(TAG(), "onReceiveValue(value): " + value);
}
});
其中url是新的哈希值.即第2页. Webview加载速度非常快:)
where url is the new hash value. i.e. Page2. Webview loads pretty fast :)
这篇关于更改Android Webview内容(哈希),而无需重新加载url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!