代码之家  ›  专栏  ›  技术社区  ›  bhups

在WebView中有没有任何方法可以截获javascript触发的URL?

  •  5
  • bhups  · 技术社区  · 15 年前

    是否有任何方法可以截获 WebView 就像普通的hrefs使用 shouldOverrideUrlLoading() ?

    1 回复  |  直到 14 年前
        1
  •  5
  •   Sergey Glotov Nitesh Khosla    14 年前

    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+");");
        }
    }