简体   繁体   English

Android 4.4的WebView中的jQuery概率

[英]jquery prob in WebView of Android 4.4

I have loaded a webpage in thw WebView and inject jquery and my js file from my asset fole to that webpage. 我已经在WebView中加载了一个网页,并将jquery和我的js文件从资产假名注入到该网页。 My code is below in short. 我的代码简而言之如下。

MainActivity.java MainActivity.java

mWebView.loadUrl("www.test.com/test.html");
mWebView.loadUrl("javascript: " + readFromfile("jquery-1.8.3.js", MainActivity.this));
mWebView.loadUrl("javascript: " + readFromfile("my_android.js", MainActivity.this));

.....................

mWebView.loadUrl("javascript: myMethod();");

my_android.js my_android.js

function myMethod(){
...............
var mySpan = $("<span id=\"myspan\"></span>");
................
}

This is running fine in pre-Kitkat. 在Kitkat之前运行良好。 But it is giving error in Kitkat. 但这在Kitkat中给出了错误。 When it is loading the JS, it is giving error: 加载JS时,出现错误:

I/chromium﹕ [INFO:CONSOLE(1)] "Uncaught ReferenceError: varrootjQuery is not defined"

When I am calling the js function, it is giving: 当我调用js函数时,它给出了:

$ is not defined

What is the problem in my code? 我的代码有什么问题? Here I like to mention all webview related code are running in UI thread only. 在这里,我想提及所有与Webview相关的代码仅在UI线程中运行。

I think you just need to wait jquery is loaded before use it. 我认为您只需要等待jquery加载后再使用它。

See this similar problem: 看到类似的问题:

https://stackoverflow.com/a/12763180/1663074 https://stackoverflow.com/a/12763180/1663074

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM