I have a bunch of html files that come with my app and are bundlet in the assets folder.
I load a page like this to my webview:
WebView webView = (WebView) findViewById(R.id.webview);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d("MyApplication", message + " -- From line " + lineNumber + " of " + sourceID);
}
});
webView.loadUrl("file:///android_asset/_lib/jquery-1.6.1.min.js");
webView.loadUrl("file:///android_asset/" + page);
Now if page contains this:
<!-- jQuery library -->
<script type="text/javascript" src = "_lib/jquery-1.6.1.min.js"></script>
<script src = "_lib/jquery.easing-1.3.js"></script>
<!-- iosSlider plugin -->
<script src = "javascript/jquery.iosslider.js"></script>
I get the following error:
Uncaught ReferenceError: jQuery is not defined at file:///android_asset/javascript/jquery.iosslider.js:32
If I load the same page from a webserver the javascript works as intended.
The problem seems to be the _ in front of the lib folder. The jquery.iosslider.js file is executed without a problem.
I removed the _ in the folder name and also in the html files and now everything just works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.