JavaScript在WebView中不起作用

时间:2011-11-17 22:54:24

标签: java javascript android webview android-webview

我正在尝试开发这种“类似云”的Android应用程序,但我无法在应用程序内部执行JavaScript。这是我活动的java部分......

这一切都很好,但是在http://www.webprogramming360.com/SpanishQuizMe/lesson.php上它需要一个JavaScript页面(它现在可以让你现在看到它),但是onClick JavaScirpt事件是一个位于这里的被调用JavaScript页面上的一个函数{{3不会执行。

如何执行该功能? javascript甚至可以工作吗? 并且Android Market Place会接受这样的应用程序(云中的应用程序/代码的主要部分是在线直播)

    package com.something.something;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class QuizSplashActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         //setContentView(R.layout.splash);

         // Let's display the progress in the activity title bar, like the
         // browser app does.
         getWindow().requestFeature(Window.FEATURE_PROGRESS);

         WebView webview = new WebView(this);
         setContentView(webview);

         webview.getSettings().setJavaScriptEnabled(true);

         final Activity activity = this;
         webview.setWebChromeClient(new WebChromeClient() {
         public void onProgressChanged(WebView view, int progress) {
              // Activities and WebViews measure progress with different scales.
              // The progress meter will automatically disappear when we reach 100%
              activity.setProgress(progress * 1000);
         }
       });

webview.setWebViewClient(new WebViewClient() {

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
         //Users will be notified in case there's an error (i.e. no internet connection)
         Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
      //This will load the webpage that we want to see
       webview.loadUrl("http://www.webprogramming360.com/SpanishQuizMe/");

    }
}

1 个答案:

答案 0 :(得分:0)

如果我运行您的代码但重定向到此链接(http://www.webprogramming360.com/cgi-sys/suspendedpage.cgi),请检查您的网址