Rajapandian
Rajapandian

Reputation: 9317

Avoid webview redirect

I have a WebView in my project and its loaded with some initial content. Now when the user clicks on the hyperlink on the WebView it should not reload the WebView, instead it should display the initial content. I tried the below code but it is not working.

detailsAndTerms.setWebViewClient(new WebViewClient(){           
    @Override  
    public boolean shouldOverrideUrlLoading(WebView view, String url) {                         
        return false;
    }
});

Please help to solve this problem. Thanks in advance.

Upvotes: 2

Views: 3826

Answers (1)

Ron
Ron

Reputation: 24235

detailsAndTerms.setWebViewClient(new WebViewClient(){           
     @Override  
     public void onPageStarted (WebView view, String url, Bitmap favicon)  
     {                          
        if (url != termsurl) {
            // stop loading page if its not the originalurl.
            detailsAndTerms.stopLoading(); 
        }
     } 

});

Update

Try returning false from the shouldOverrideUrlLoading method.

     public boolean shouldOverrideUrlLoading(WebView view, String url)  
     {                          
        return true;
     } 

Upvotes: 3

Related Questions