gpt4 book ai didi

android - 在 android 4.4 上加载 Assets 文件时未捕获 ReferenceError

转载 作者:太空宇宙 更新时间:2023-11-03 12:55:50 24 4
gpt4 key购买 nike

我正在使用以下 MathJax 应用程序代码。 http://cs.jsu.edu/wordpress/?p=498#comment-217

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

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

在 android 4.4 模拟器上运行时,出现以下错误。

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)

更新:采纳了ksasq的建议后,这是我的新代码,但仍然无法正常工作。

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", "");

最佳答案

您必须将所有行 loadUrl(...) 替换为 evaluateJavascript(...)。但这仅适用于 KitKat(API 19 或更高版本),因此您需要先进行 SDK 版本检查:

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

关于android - 在 android 4.4 上加载 Assets 文件时未捕获 ReferenceError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20582282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com