在 Android webview 中禁用页面转发

问题描述:

我有一个显示广告(不是我的广告)的网络视图,问题是当用户点击x"按钮退出广告时,广告仍将他们定向到某个网站.我想知道的是,由于我无法控制广告,我可以在 webview 中禁用页面定向/转发吗?这意味着即使用户点击我的 webview 中的链接也不会发生任何事情.

I have a webview that shows ads (not my ads), the problem is when user clicks the "x" button to exit the ad, the ad still directs them to a site. What I wonder is since I can't control the ads, can I instead Disable page directing/forwarding inside webview? that means even if user clicks a link inside my webview nothing should happen.

您正在寻找 WebClient.shouldOverrideUrlLoading 方法.

You are looking for WebClient.shouldOverrideUrlLoading method.

 webview.setWebViewClient(new WebViewClient() {
   public boolean shouldOverrideUrlLoading (WebView view, String url){
       //True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.
       return true;
   }
 });