E/Web Console(8272): Uncaught ReferenceError: functionName is not defined:1 while loading webviews in a View Pager

前端 未结 3 1239
星月不相逢
星月不相逢 2021-01-21 14:47

I am trying to load webviews in a view pager.

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanc         


        
3条回答
  •  感情败类
    2021-01-21 15:05

    I had a fix on this

    just set webChromeClient and catch the error and reload the page...

        myWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                isLoading = true;
            }
    
            @Override
            public void onPageFinished(WebView view, String url) {
                myWebView.loadUrl("javascript:testFunction()");
            }
        });
    
        myWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
                MessageLevel level = consoleMessage.messageLevel();
                if(level.ordinal() == 3) { // Error ordinal
                    if(loading) {
                        myWebView.stopLoading();
                        myWebView.loadUrl(AppConstants.ARTICLE_PAGE_URL);
                    }
                }
            }
            return false;
        }
    

提交回复
热议问题