Android Calling JavaScript functions in WebView

前端 未结 7 722
夕颜
夕颜 2020-11-22 04:14

I am trying to call some javascript functions sitting in an html page running inside an android webview. Pretty simple what the code

7条回答
  •  野的像风
    2020-11-22 04:51

    Yes you have the syntax error. If you want to get your Javascript errors and printing statements in your logcat you must implement the onConsoleMessage(ConsoleMessage cm) method in your WebChromeClient. It gives the complete stack traces like Web console(Inspect element). Here is the method.

    public boolean onConsoleMessage(ConsoleMessage cm) 
        {
            Log.d("Message", cm.message() + " -- From line "
                                 + cm.lineNumber() + " of "
                                 + cm.sourceId() );
            return true;
        }
    

    After implementation you will get your Javascript errors and print statements (console.log) on your logcat.

提交回复
热议问题