问题
How to add JQuery library into page loaded in Android WebView? My WebView with page:
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(url);
回答1:
I had to remove escapes from js code (like \n). Also I had to wait untill JQuery is loaded:
load.tryReady = function(time_elapsed) {
// Continually polls to see if jQuery is loaded.
if (typeof $ == "undefined") { // if jQuery isn't loaded yet...
if (time_elapsed <= 5000) { // and we havn't given up trying...
setTimeout("load.tryReady(" + (time_elapsed + 200) + ")", 200); // set a timer to check again in 200 ms.
} else {
alert("Timed out while loading jQuery.")
}
} else {
// Any code to run after jQuery loads goes here!
}
}
http://www.coderanch.com/t/504284/HTML-CSS-JavaScript/dynamically-load-jQuery-javascript-library
来源:https://stackoverflow.com/questions/12759060/how-to-add-jquery-or-any-js-library-into-page-loaded-in-android-webview