2015-08-22 30 views
0

我正尝试从Web视图的资产文件夹中加载本地js文件。JavaScript在下面的WebView中无法使用Android 4.4.4

它在Android 4.4.4和Android 5下完美工作,但不在Android 4.3和更低版本下工作。

css显示正确,但js似乎没有加载。

这是我的代码:

private static final String HTML_CHARSET = "<meta charset='utf-8'>"; 
private static final String HTML_TITLE = "<title>Aufbau einer Tabelle</title>"; 
private static final String HTML_STYLESHEET = "<link href='matrix.css' type='text/css' rel='stylesheet'/>"; 
private static final String HTML_SCRIPT1 = "<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js' type='text/javascript'></script>"; 
private static final String HTML_SCRIPT2 = "<script src='https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js' type='text/javascript'></script>"; 
private static final String HTML_SCRIPT3 = "<script src='matrix.js' type='text/javascript'></script>"; 
private static final String HTML_VIEWPORT = "<meta name='viewport' content='width=device-width, initial-scale=1.0'>"; 

private static final String HTML_STRING = "<!doctype html> <html> <head> " + HTML_CHARSET + HTML_TITLE + HTML_STYLESHEET + HTML_SCRIPT1 + HTML_SCRIPT2 + HTML_SCRIPT3 + HTML_VIEWPORT + "</head> <body> <table> %s%s </table> </body> </html>"; 

...

String htmlString = String.format(HTML_STRING, htmlTableHeader, tableBody); 

    WebSettings settings = matrixWebView.getSettings(); 
    settings.setJavaScriptEnabled(true); 
    settings.setDomStorageEnabled(true); 

    matrixWebView.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "UTF-8", null); 

任何人有一个想法?

回答

0

loadDataWithBaseURL不需要以“file://”或路径作为前缀。它只需要HTML内容。

loadURL可用于加载文件内容。

相关问题