Don't navigate to other pages in WebView,disable links and references

后端 未结 8 1742
再見小時候
再見小時候 2020-12-25 12:02

I have a webView in Android, and I open a html webpage in it. But it\'s full of links and images, and when I click one of them, it loads in my webview. I want to disable thi

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 12:38

    If you want to open inner link of a web page in different window then

    Don't use

    WebView webView;//Your WebView Object
    webView.setWebViewClient(new HelpClient());// Comment this line
    

    B'coz setWebViewClient() method is taking care of opening a new page in the same webview. So simple comment this line.

    private class HelpClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals("www.example.com")) {
                // This is my web site, so do not override; let my WebView load the page
                return false;
            }
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    }
    

    Hope this will work.

提交回复
热议问题