Open external link inside the webview main page

Asked

Viewed 2,475 times

1

I have an application loaded in 100% on WebView, i put the link where has the application and the entire application is via web in php.

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

My attempt:

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

But it opens inside itself WebView, i would like only the links of the web pages of the application to load inside the Webview and external links to be loaded outside.

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

1 answer

2


You need to implement the 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 cause all links to open inside the webView.

  • hi Eonardo, thank you for your attention to my problem. .então.. it already happens.. i want only links that are not part of the page open outside the webview.. pq google for example is loading in .. I want only files from the webview main site to be uploaded. links that are not part like google for example open outside the webview browser..

  • I edited my answer, you need to put an IF, if the requested url has a piece of your website url, open inside the webview, otherwise open outside.

  • Valeuuuuuuuuuuuuuuuuuuuuuuuuuu Leonardo Tks for your help!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.