覆盖Android上的函数shouldInterceptRequest

时间:2016-04-04 15:35:37

标签: nativescript

我无法在Android上覆盖WebViewClient函数shouldInterceptRequest。没有错误,但没有调用该函数。我错过了什么?

函数shouldInterceptRequest()的文档; http://developer.android.com/reference/android/webkit/WebViewClient.html

if(application.android){
    try{
        android.webkit.WebViewClient.extend({
              shouldInterceptRequest: function(_webView,webResourceRequest){
                    alert('shouldInterceptRequest is called');                            
                    return null;
             } 
       });
    }catch(e){                       
          alert(e.message);
    }
}

1 个答案:

答案 0 :(得分:0)

我没有看到您将WebViewClient设置为WebView。尝试做类似的事情:

   var myWebView = page.getViewById("myWebView"); 
   if (myWebView.android) {
       try {
          var MyWebViewClient = android.webkit.WebViewClient.extend({
              shouldInterceptRequest: function(_webView,webResourceRequest){
                    alert('shouldInterceptRequest is called');                            
                    return null;
             } 
          });
          myWebView.android.setWebViewClient(new MyWebViewClient());
       } catch(e) {                       
              alert(e.message);
       }
    }