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 this behaviour, so if I click on a link, don't load it. I've tried this solution and edited a bit for myselft, but not worked. My webviewclient code:
private boolean loaded = false; @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if(loaded == false){ view.loadUrl(url); loaded = true; return true; }else{ return false; } } My webview implementation and settings.
WebView wv = (WebView) findViewById(R.id.recipeWv); ourWebViewClient webViewClient = new ourWebViewClient(); webViewClient.shouldOverrideUrlLoading(wv, URLsave); wv.setWebViewClient(webViewClient); wv.setFocusableInTouchMode(false); wv.setFocusable(false); wv.setClickable(false); WebSettings settings = wv.getSettings(); settings.setDefaultTextEncodingName("utf-8"); settings.setLoadWithOverviewMode(true); settings.setBuiltInZoomControls(true); Example: If the user open in my webview the StackOverflow homepage and clicks on one of the links(like "Questions") then the webview should stay on the StackOverflow homepage.