简体   繁体   中英

Android Webview not loading url if the href starts with “www”

I am loading webview from a string fetched from an api call. But if the href for the hyperlink starts with "www", then clicking on that link makes the webview blank. If href starts with " http://www " then the url is getting loaded. Is there any way to make the hyperlink work properly.

You could check the url in your code, like this:

webView.setWebViewClient(new WebViewClient() { 
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                if(!url.startsWith("http://"))
                {
                    url = "http://" + url;
                }
                webView.loadUrl(url); 
                return false; 
            } 
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM