【问题标题】:JavaScript is not working in webView loaded from assetJavaScript 在从资产加载的 webView 中不起作用
【发布时间】:2013-09-23 18:04:33
【问题描述】:

我正在尝试将offline version of python documentationasset文件夹加载到webview。离线文档在我的电脑网络浏览器中离线运行时完美运行,但在 webview(类似于 jquery is missing)中无法正常运行。

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.wrapper);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl("file:///android_asset/python/index.html");
    }

}

当我尝试加载主页或导航到任何页面时,都会显示此错误消息。

09-24 01:03:02.789: E/Web Console(479): ReferenceError: Can't find variable: $ at file:///android_asset/python/index.html:164

我错过了什么?

【问题讨论】:

  • 不确定但通常这必须工作 WebView webView = (WebView) findViewById(R.id.wrapper); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("file:///android_asset/index.html");

标签: javascript android jquery android-webview


【解决方案1】:

好的,这不会像我打算像 phonegap 应用程序那样工作。我正在使用 Java 在 Android 平台上工作。网页现在像其他安卓应用程序一样正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-06
    • 2015-02-02
    • 2011-03-10
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    相关资源
    最近更新 更多