Uncaught ReferenceError while loading asset file on android 4.4

后端 未结 4 1579
野的像风
野的像风 2020-12-18 11:41

I am using following MathJax app code. http://cs.jsu.edu/wordpress/?p=498#comment-217

In following function i am trying to load file from asset directory.



        
相关标签:
4条回答
  • 2020-12-18 11:49

    You have to replace all the lines loadUrl(...) with evaluateJavascript(...). But this is only for KitKat (API 19 or above), so you need to do an SDK version check first:

    if (android.os.Build.VERSION.SDK_INT < 19) {
        mWebView.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
    } else {
        mWebView.evaluateJavascript("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);",null);
    }
    
    0 讨论(0)
  • 2020-12-18 12:00
    if (android.os.Build.VERSION.SDK_INT < 19) {
                        v.loadUrl(url);
                    } else {
                        v.evaluateJavascript(url,null);
                    }
    
    0 讨论(0)
  • 2020-12-18 12:04

    It looks like the MathJax variable won't be set until you load the <script> tag. You should move this into an onload listener. Something like:

    <script type='text/x-mathjax-config'>
       function setupMathJax() {
         MathJax.Hub.Config(...);
       }
    </script>
    <script type='text/javascript' src='file:///android_asset/MathJax/MathJax.js'></script>
    <body onload='setupMathJax()'>
    <span id='math'></span>
    </body>
    
    0 讨论(0)
  • 2020-12-18 12:09

    Perhaps the first <script> containing your function setupMathJax() is getting executed before your second <script> has loaded your MathJax file, causing the exception where MathJax is not defnied. Try reversing the order of those tags.

    0 讨论(0)
提交回复
热议问题