Ven*_*h S 20 javascript java android webview mathjax
This is my main activity
package com.example.mathjax_issues;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView)findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl("file:///android_asset/MathJax/test/sample-asciimath.html");
// String html="<!DOCTYPE html> <html> <head> <title>MathJax AsciiMath Test Page</title> <!-- Copyright (c) 2012-2013 The MathJax Consortium --> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /> <script type=\"text/javascript\" src=\"file:///android_asset/MathJax/MathJax.js?config=AM_HTMLorMML-full\"></script> </head> <body> <p> When `a != 0`, there are two solutions to `ax^2 + bx + c = 0` and they are </p> <p style=\"text-align:center\"> `x = (-b +- sqrt(b^2-4ac))/(2a) .` </p> </body> </html> ";
// Log.e("html",html);
// webView.loadDataWithBaseURL("file:///android_asset/MathJax", html, "text/html","utf-8", "");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private class MyWebViewClient extends WebViewClient
{
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
}
}
Run Code Online (Sandbox Code Playgroud)
This my sample-asciimath.html
<!DOCTYPE html>
<html>
<head>
<title>MathJax AsciiMath Test Page</title>
<!-- Copyright (c) 2012-2013 The MathJax Consortium -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript" src="../MathJax.js?config=AM_HTMLorMML-full"></script>
</head>
<body>
<p>
When `a != 0`, there are two solutions to `ax^2 + bx + c = 0` and they are
</p>
<p style="text-align:center">
`x = (-b +- sqrt(b^2-4ac))/(2a) .`
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
below is the image of my project

when compiling this code in 2.3.3,2.2,4.1.2,4.2.2 latest versions
I get the correct output from the source

but when i compiled the same source in 3.0,3.1 and 4.0.3,4.0.4 android version
I am getting the wrong output like this

Friends pls help me ... I am unable to solve this error ... I think there may be a javascript problem.Hope you guys give me some idea
I am storing the mathjax locally .. in assets
Thanks in advance ...
我遇到了类似的问题.我所做的是将所有.js文件复制到与html相同的目录中,并按如下方式添加.
<script type="text/javascript" src="MathJax.js"></script>
Run Code Online (Sandbox Code Playgroud)
我知道这听起来有点愚蠢,但它确实奏效了.
如果这不起作用,请将.js文件复制到html文件本身并像在标题中一样尝试:
<script type="text/javascript">
copy the whole MathJax.js and paste it here
</script>
Run Code Online (Sandbox Code Playgroud)
有些人已经遇到了这个问题(实际上……很多人……)。
一篇文章(还有一个答案)引起了我的注意:/sf/answers/503842391/
看来您必须在文档完全加载后在 WebViewClient 中手动注入 Javascript 调用。我没有更多的解释,但也许你可以尝试这种方式!
| 归档时间: |
|
| 查看次数: |
5202 次 |
| 最近记录: |