I have a hybrid app that uses WebView to render external html from my own site. It had a problem that if any link was clicked, it started a browser window. I found this code to help me out and it works:
myWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
But now the problem is that I want it to not work for links that have target=_blank in them. So any normal links still open inside the WebView while the links with target=_blank should open in new browser window.
Any way we can do this?
Thanks
One more setting required for webview in addition to myWebView.getSettings().setSupportMultipleWindows(true); myWebView.setJavaScriptCanOpenWindowsAutomatically(true);
Try this.
Reference: Carson Ip
First,
mWebView.getSettings().setSupportMultipleWindows(true);
Then in
WebChromeClient
, overrideOnCreateWindow()