未捕获的Ref​​erenceError而在Android 4.4系统加载资源文件 [英] Uncaught ReferenceError while loading asset file on android 4.4

查看:493
本文介绍了未捕获的Ref​​erenceError而在Android 4.4系统加载资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的MathJax应用code。 http://cs.jsu.edu/word$p$ PSS / P = 498#评论-217

在下面的函数我试图从资产目录中加载文件。

 公共静态布尔makeMathView_new(的WebView的WebView){
            webview.getSettings()setRenderPriority(RenderPriority.HIGH)。
            webview.getSettings()setJavaScriptEnabled(真)。
            webview.loadDataWithBaseURL(HTTP://栏,<脚本类型=文本/ X-mathjax  - 配置>中
                    +MathJax.Hub.Config({messageStyle:'无',showMathMenu:假的,JAX:['输入/特,输出/ HTML,CSS'],
                    +扩展:['tex2jax.js'],
                +的HTML CSS:{规模:100},
                    +的TeX:{扩展:['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js']}});&其中; /脚本>中
                +<脚本类型=文/ JavaScript的SRC =文件:///android_asset/MathJax/MathJax.js'>< / SCRIPT>中
                +<跨度ID ='数学'>< / SPAN>中,text / html的,UTF-8,);


        返回true;
    }
 

在Android 4.4模拟器上运行时,我收到以下错误。

  V / WebViewChromium(1342):铬绑定到后台活套活套{b1da1340}
 I /铬(1342):[INFO:library_loader_hooks.cc(112)]铬启用日志记录:级别= 0,默认的详细程度= 0
 I / BrowserProcessMain(1342):初始化铬工艺,提炼= 0
 W /铬(1342):警告:proxy_service.cc(888)PAC支持禁用,因为没有系统的实现
 E /铬(1342):[错误:gl_surface_egl.cc(153)未找到合适的EGL的configs。
 E /铬(1342):[错误:gl_surface_egl.cc(620)] GLSurfaceEGL :: InitializeOneOff失败。
 E /铬(1342):[错误:gl_surface_egl.cc(153)未找到合适的EGL的configs。
 E /铬(1342):[错误:gl_surface_egl.cc(620)] GLSurfaceEGL :: InitializeOneOff失败。
 E /铬(1342):[错误:gpu_info_collector.cc(86)] GFX :: GLSurface :: InitializeOneOff()失败

I /铬(1101):信息:控制台(1)]未捕获的Ref​​erenceError:MathJax没有定义,出处:http://酒吧/(1)
 

更新:结合ksasq的建议后,这是我的新的code,但它仍然没有工作。

  webview.loadDataWithBaseURL(HTTP://栏,<脚本类型=文本/ X-mathjax  - 配置>中
      +功能setupMathJax(){
                +MathJax.Hub.Config({messageStyle:'无',showMathMenu:假的,JAX:['输入/特,输出/ HTML,CSS'],
                    +扩展:['tex2jax.js'],HTML-CSS:{规模:100},
                    +的TeX:{扩展:['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js']}});
     +}
                +&所述; /脚本>中
                +<脚本类型=文/ JavaScript的SRC =文件:///android_asset/MathJax/MathJax.js'>< / SCRIPT>中
     +<身体的onload ='setupMathJax()>中
                +<跨度ID ='数学'>< / SPAN>中
     +< /身体GT;
                text / html的,UTF-8,);
 

解决方案

您必须更换所有的行使用loadURL(...) evaluateJavascript(...)。但是,这仅仅是奇巧(API 19或以上),所以你需要首先做一个SDK版本检查:

 如果(android.os.Build.VERSION.SDK_INT< 19){
    mWebView.loadUrl(JavaScript的:MathJax.Hub.Queue(['排版,MathJax.Hub]););
} 其他 {
    mWebView.evaluateJavascript(JavaScript的:MathJax.Hub.Queue(['排版,MathJax.Hub]);,NULL);
}
 

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.

public static boolean makeMathView_new(WebView webview) {
            webview.getSettings().setRenderPriority(RenderPriority.HIGH);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.loadDataWithBaseURL("http://bar", "<script type='text/x-mathjax-config'>"
                    +"MathJax.Hub.Config({ messageStyle: 'none', showMathMenu: false, jax: ['input/TeX','output/HTML-CSS'], "
                    +"extensions: ['tex2jax.js'],"         
                + "'HTML-CSS': { scale: 100 },"              
                    +"TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'] } });</script>"
                +"<script type='text/javascript' src='file:///android_asset/MathJax/MathJax.js'></script>" 
                + "<span id='math'></span>","text/html","utf-8", "");


        return true;
    }

When running on android 4.4 emulator, I am getting following errors.

V/WebViewChromium(1342): Binding Chromium to the background looper Looper{b1da1340}
 I/chromium(1342): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
 I/BrowserProcessMain(1342): Initializing chromium process, renderers=0
 W/chromium(1342): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
 E/chromium(1342): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
 E/chromium(1342): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
 E/chromium(1342): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
 E/chromium(1342): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
 E/chromium(1342): [ERROR:gpu_info_collector.cc(86)] gfx::GLSurface::InitializeOneOff() failed

I/chromium(1101): [INFO:CONSOLE(1)] "Uncaught ReferenceError: MathJax is not defined", source: http://bar/ (1)

Update: After incorporating ksasq's suggestion , Here is my new code but it is still not working.

webview.loadDataWithBaseURL("http://bar", "<script type='text/x-mathjax-config'>"
      + "function setupMathJax() {"
                + "MathJax.Hub.Config({ messageStyle: 'none', showMathMenu: false, jax: ['input/TeX','output/HTML-CSS'], "
                    +"extensions: ['tex2jax.js'],'HTML-CSS': { scale: 100 },"            
                    +"TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'] } });" 
     + "}"
                + "</script>"
                + "<script type='text/javascript' src='file:///android_asset/MathJax/MathJax.js'></script>" 
     + "<body onload='setupMathJax()'>"
                + "<span id='math'></span>" 
     + "</body>"
                ,"text/html","utf-8", "");

解决方案

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);
}

这篇关于未捕获的Ref​​erenceError而在Android 4.4系统加载资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆