How to add JQuery (or any) js library into page loaded in Android WebView?

瘦欲@ 提交于 2019-12-23 04:21:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!