机器人的WebView不加载JavaScript文件,但Android浏览器加载它细 [英] Android WebView not loading a JavaScript file, but Android Browser loads it fine

查看:385
本文介绍了机器人的WebView不加载JavaScript文件,但Android浏览器加载它细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写它连接到一个后台办公室的网站的应用程序。在后台网站包含的JavaScript函数整体转换,至少100倍的平均网站。遗憾的是它并没有加载它们,并导致许多功能无法正常工作。于是我运行一个测试。我把网页从我的服务器,加载FireBugLite JavaScript的文字。其大量的JavaScript和完善的测试,看看在Android的WebView将加载它。 web视图加载不算什么,但浏览器加载Firebug图标。究竟会赚取差价,为什么能在浏览器在我的WebView运行,而不是?任何建议。

I'm writing an application which connects to a back office site. The backoffice site contains a whole slew of JavaScript functions, at least 100 times the average site. Unfortunately it does not load them, and causes much of the functionality to not work properly. So I am running a test. I put a page out on my server which loads the FireBugLite javascript text. Its a lot of javascript and perfect to test and see if the Android WebView will load it. The WebView loads nothing, but the browser loads the Firebug Icon. What on earth would make the difference, why can it run in the browser and not in my WebView? Any suggestions.

更多的背景信息,为了得到车位的Droid(除Windows或其它任何平台)的臭的后台应用程序,我需要欺骗bakcoffice应用相信什么访问该网站的Internet Explorer。我这样做,通过修改的WebView用户代理。

More background information, in order to get the stinking backoffice application available on a Droid (or any other platform except windows) I needed to trick the bakcoffice application to believe what's accessing the website is Internet Explorer. I do this by modifying the WebView User Agent.

也因为这个应用程序,我已经瘦身目标网页,这样我就可以给你向我提供援助的来源。

Also for this application I've slimmed my landing page, so I could give you the source to offer me aid.

package ksc.myKMB;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebSettings; 
import android.webkit.WebViewClient;
import android.widget.Toast;

public class myKMB extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); /** Performs base set up */

        /** Create a Activity of this Activity, IE myProcess */
        myProcess = this;

        /*** Create global objects and web browsing objects */
        HideDialogOnce = true;
        webview = new WebView(this) {

        };
        webChromeClient = 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%
          myProcess.setProgress((progress * 100));
          //CreateMessage("Progress is : " + progress);
              }
        };
        webViewClient = new WebViewClient() {
          public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                 Toast.makeText(myProcess, MessageBegText + description + MessageEndText, Toast.LENGTH_SHORT).show();
               }  
          public void onPageFinished (WebView view, String url) {
              /** Hide dialog */
           try {
           // loadingDialog.dismiss();  
           } finally {

           }

           //myProcess.setProgress(1000);
           /** Fon't show the dialog while I'm performing fixes */
              //HideDialogOnce = true;
view.loadUrl("javascript:document.getElementById('JTRANS011').style.visibility='visible';");

          }

          public void onPageStarted(WebView view, String url, Bitmap favicon) {

       if (HideDialogOnce == false) {
         //loadingDialog = ProgressDialog.show(myProcess, "", 
                //   "One moment, the page is laoding...", true);
       } else {
        //HideDialogOnce = true;
       }
      }

    };


    getWindow().requestFeature(Window.FEATURE_PROGRESS);
            webview.setWebChromeClient(webChromeClient);
    webview.setWebViewClient(webViewClient);
    setContentView(webview);


    /** Load the Keynote Browser Settings */
    LoadSettings();
    webview.loadUrl(LandingPage);


}

    /** Get Menu */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.menu, menu);
     return true;
    }

    /** an item gets pushed */
    @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  // We have only one menu option
  case R.id.quit:
   System.exit(0);
   break;
  case R.id.back:
   webview.goBack();
  case R.id.refresh:
   webview.reload();
  case R.id.info:
   //IncludeJavascript("");
  }
  return true;
 }


/** Begin Globals */
public WebView webview;
public WebChromeClient webChromeClient;
public WebViewClient webViewClient;
public ProgressDialog loadingDialog; 
public Boolean HideDialogOnce; 
public Activity myProcess;
public String OverideUserAgent_IE = "Mozilla/5.0 (Windows; MSIE 6.0; Android 1.6; en-US) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2 myKMB/1.0";
public String LandingPage = "http://kscserver.com/main-leap-slim.html";
public String MessageBegText = "Problem making a connection, Details: ";
public String MessageEndText = " For Support Call: (xxx) xxx - xxxx.";

public void LoadSettings() {

 webview.getSettings().setUserAgentString(OverideUserAgent_IE);
 webview.getSettings().setJavaScriptEnabled(true);
 webview.getSettings().setBuiltInZoomControls(true);
 webview.getSettings().setSupportZoom(true);
}

/** Creates a message alert dialog */
public void CreateMessage(String message) {

 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 builder.setMessage(message)
        .setCancelable(true)
        .setNegativeButton("Close", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
           dialog.cancel();
          }
        });
 AlertDialog alert = builder.create();
 alert.show();
}


}

我的应用程序在后台运行,并且你可以看到在右下角没有萤火虫。然而,浏览器(顶部的仿真器)具有相同的页面,但显示了萤火虫。我究竟做错了什么?我假设分配给应用程序,过程中的功率分配,或物理内存的东西它可能是没有足够的内存。我不知道,我只知道结果是奇怪的。

My Application is running in the background, and as you can see no Firebug in the lower right hand corner. However the browser (the emulator on top) has the same page but shows the firebug. What am I doing wrong? I'm assuming its either not enough memory allocated to the application, process power allocation, or a physical memory thing. I can't tell, all I know is the results are strange.

我得到同样的事情形成我的Andr​​oid设备,应用程序显示没有萤火,但浏览器显示的萤火虫。

I get the same thing form my android device, the application shows no firebug but the browser shows the firebug.

我已经对JavaScript的Web浏览器上,这个问题是Web视图从网络浏览器作用不同。

I already have JavaScript on the web browser on, the problem is the web view is acting to different from the web browser.

推荐答案

工作好了。我可以看到的WebView萤火虫图标。

Works just great for me. I can see FireBug icon in WebView.

这行是邪恶的,我想你应该将其删除:

This line is evil, I guess you should remove it:

webview.getSettings().setUserAgentString(OverideUserAgent_IE);

这篇关于机器人的WebView不加载JavaScript文件,但Android浏览器加载它细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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