Issue
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.
But if I use Webview2.loadurl() everytime, it takes time to load. Instead I want to just change the content without reloading it.
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.
Solution
I've figured it out :
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);
}
});
where url is the new hash value. i.e. Page2. Webview loads pretty fast :)
Answered By - Rakesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.