Uncaught ReferenceError while loading asset file on android 4.4

做~自己de王妃 提交于 2019-11-29 12:10:23

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);
}
if (android.os.Build.VERSION.SDK_INT < 19) {
                    v.loadUrl(url);
                } else {
                    v.evaluateJavascript(url,null);
                }

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>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!