【问题标题】:Is there any way to intercept javascript triggered URL in webview?有没有办法在 webview 中拦截 javascript 触发的 URL?
【发布时间】:2010-08-26 06:50:48
【问题描述】:

有什么方法可以像使用shouldOverrideUrlLoading() 的普通href 一样拦截WebView 中的javascript 触发URL?

【问题讨论】:

    标签: javascript android android-webview


    【解决方案1】:

    onLoadResource() 在调用任何资源时调用,包括 JavaScript。目的与shouldOverrideUrlLoading() 有点不同。

    webControls.setWebViewClient(new WebViewClient() { 
        //Notify the host application that the WebView will load 
        //the resource specified by the given url.
        @Override  
        public void onLoadResource (WebView view, String url) {
            super.onLoadResource(view, url);
            Log.v(TAG, "onLoadResource("+url+");");
        }
    
        //Give the host application a chance to take over the 
        //control when a new url is about to be loaded in the 
        //current WebView. 
        @Override  
        public void shouldOverrideUrlLoading(WebView view, String url) {
            super.shouldOverrideUrlLoading(view, url);
            Log.v(TAG, "shouldOverrideUrlLoading("+url+");");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-19
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多