Open external link inside webview main page

1

I have an application loaded at 100% in WebView , I put the link where it has the application and the whole application is via web in php.

Only you have links that are not part of the page that are external links (example www.google.com.br ) and would like it to open in the browser itself and not within WebView

My attempt:

<a href="https://www.google.com.br" target="_blank"> busca </a>

But it opens within the WebView itself, I would like only the links from the application web pages to load inside the 'WebView and external links to be loaded out.

Is this possibility possible? Where do I have to change to get this result?

    
asked by anonymous 21.09.2016 / 19:33

1 answer

2

You need to implement shouldOverrideUrlLoading

example:

myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (url.contains("http://www.seuendereco.com")) {
                myWebView.loadUrl(url);
                return false;
            } else {
               Intent intent = new Intent(Intent.ACTION_VIEW);
               intent.setData(Uri.parse(url));
               startActivity(intent);
               return true;
            }

        }
    });

This code will make all links open within the webView.

    
21.09.2016 / 19:45