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

前端 未结 3 1237
星月不相逢
星月不相逢 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 14:59

    I was getting Uncaught Reference Error: JavascriptInterfaceName is not defined on every second startup of my hybrid application on 4.3 and below, and so I did this thanks to @Abi in my WebChromeClient class:

    @Override
    @SuppressLint({"AddJavascriptInterface", "InflateParams"})
    public boolean onConsoleMessage(@NonNull ConsoleMessage consoleMessage) {
        if("Uncaught ReferenceError: JavascriptInterfaceName is not defined".equals(consoleMessage.message())) {
            webView.addJavascriptInterface(new WebAppInterface(), "JavascriptInterfaceName ");
            webView.reload();
        }
        return super.onConsoleMessage(consoleMessage);
    }
    

    And it works! Thank you very much!

提交回复
热议问题