Android WebView target=”_blank”

We were having a separate WebView fragment, which was called different urls passed to it.
But a problem with the new versions of Android came up: The WebView couldn’t load links with attribute target=’_blank’. To work around this issue I declared a WebChromeClient opening a new webview with the url from the href.


mWebView.setWebChromeClient(new WebChromeClient() {


            public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture,
                    Message resultMsg) {
                WebView.HitTestResult result = view.getHitTestResult();
                String data = result.getExtra();
                Log.d("DATA", "" + data);
                // view.loadUrl(data);

                WebView newWebView = new WebView(view.getContext());
                WebView.WebViewTransport transport =
                        (WebView.WebViewTransport) resultMsg.obj;

                return true;


You may also like...