Android的:不能让JavaScript来,即使setJavaScriptEnabled工作的WebView(真) [英] Android: can't get javascript to work on WebView even with setJavaScriptEnabled(true)

查看:1881
本文介绍了Android的:不能让JavaScript来,即使setJavaScriptEnabled工作的WebView(真)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完整的小白到Android,这只是一个简单的测试。 基于它在本教程中。

I'm a complete noob to Android and this is just a simple test. Based it on this tutorial.

下面那张HelloWebApp.java

Here goes the HelloWebApp.java

package com.company.something;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebApp extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        WebView webView = (WebView)findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("file:///android_asset/www/index.html");
    }
}

这是从水库/布局/ main.xml中:

And this is from res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/webView"
    />
</LinearLayout>

另外这是我改的清单:

Plus this is all I changed on the Manifest:

<activity android:name=".HelloWebApp"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="landscape">

对于JavaScript的,我已经竭尽所能。复杂的,简单,身体内部的底部,在一个按钮,在头上。没有什么作品。该HTML正常工作。

As for the javascript, I've tried everything. Complicated, simple, inside the body at the bottom, in a button, on the head. Nothing works. The html works fine.

在此先感谢您的帮助。

推荐答案

您错过了部分在他补充说。

You missed the part in the tutorial where he adds

webView.setWebChromeClient(new WebChromeClient());

添加之后

webView.getSettings().setJavaScriptEnabled(true);

的<一个href="http://developer.android.com/reference/android/webkit/WebView.html#setWebChromeClient(android.webkit.WebChromeClient)"相对=nofollow> Javadoc获得方法说:

设定了镀铬处理。这是WebChromeClient的处理Javascript的对话框,网页图标,标题和进度使用的实现。这将取代当前的处理程序。

Sets the chrome handler. This is an implementation of WebChromeClient for use in handling Javascript dialogs, favicons, titles, and the progress. This will replace the current handler.

这篇关于Android的:不能让JavaScript来,即使setJavaScriptEnabled工作的WebView(真)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆