Reputation: 7306
I load HTML to my WebView with
this.webViewer.loadDataWithBaseURL(BASE_URL, completeNewsTemplate,
"text/html", "UTF-8", null);
Where BASE_URL = "http://www.example.ru" i use it for WebView loading images with relative images src's
if in HTML soruce i got href link like
<a href="http://www.example.ru" target="_blank">Example</a>
Then it's just reload current webview, and target attribute does make anything for open new window.
How make webview open link in new window?
Upvotes: 0
Views: 2567
Reputation: 7306
Here is solution.
If your link equals base url WebView think that you want work with current page only.
You can try catch it like
webViewer.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
System.out
.println("DetailViewActivity.onCreate(...).new WebViewClient() {...}.onPageStarted()");
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
System.out
.println("DetailViewActivity.onCreate(...).new WebViewClient() {...}.onPageFinished()");
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out
.println("DetailViewActivity.onCreate(...).new WebViewClient() {...}.shouldOverrideUrlLoading()");
return false;
}
});
But then you click to your link in webView you never get fired shouldOverrideUrlLoading or onPageStarted only onPageFinished with your base_url.
So my solition is use for base url another domain without www prefix.
Here example if you domain www.example.com use base url example.com
Upvotes: 1