title: How can i block or avoid popup in webview?
body: <p>the webpage have some popup ads is there any way to prevent the popup from loading when the popup loads the main site doesnt appears is there any way to load the main page with out popups and how can i add a download handler l mean the webview should support downloading .torrent file </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      private WebView webView;
      private ProgressBar progressBar;
      private LinearLayout layoutProgress;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          webView = (WebView) findViewById(R.id.webView);
          progressBar = (ProgressBar) findViewById(R.id.progressBar);
          layoutProgress = (LinearLayout) findViewById(R.id.layoutProgress);
          webView.setVisibility(View.GONE);
          WebSettings settings = webView.getSettings();
          settings.setJavaScriptEnabled(true);
          settings.setBuiltInZoomControls(true);
          settings.setSupportZoom(true);
          settings.setDisplayZoomControls(false);
          webView.setWebViewClient(new WebViewClient() {
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  view.loadUrl(url);
                  return true;
              }
  
              @Override
              public void onPageFinished(WebView view, String url) {
                  webView.setVisibility(View.VISIBLE);
                  layoutProgress.setVisibility(View.GONE);
                  progressBar.setIndeterminate(false);
                  super.onPageFinished(view, url);
  
              }
              public void but(View v){
  
              }
  
              @Override
              public void onPageStarted(WebView view, String url, Bitmap favicon) {
                  layoutProgress.setVisibility(View.VISIBLE);
                  progressBar.setIndeterminate(true);
                  super.onPageStarted(view, url, favicon);
              }
          });
          if(isOnline()) {
              webView.loadUrl("http://testsite.com/");
          } else {
              String summary = "&lt;html&gt;&lt;body&gt;&lt;font color='red'&gt;No Internet Connection&lt;/font&gt;&lt;/body&gt;&lt;/html&gt;";
              webView.loadData(summary, "text/html", null);
              toast("No Internet Connection.");
          }
      }
      private void toast(String message) {
          Toast.makeText(this, message, Toast.LENGTH_LONG).show();
      }
  
      public void onBackPressed() {
          if(webView.canGoBack()) {
              webView.goBack();
          } else {
              super.onBackPressed();
          }
      }
  
      private boolean isOnline() {
          ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo netInfo = cm.getActiveNetworkInfo();
          return (netInfo != null &amp;&amp; netInfo.isConnected());
      }
      public void but(View v){
  
          webView.loadUrl("http://testsite.com/");
      }
  }
  </code></pre>