2010-06-03 91 views
13

我正在編寫連接到後臺辦公網站的應用程序。後臺網站包含一整套JavaScript功能,至少是平均網站的100倍。不幸的是,它不會加載它們,並導致很多功能無法正常工作。所以我正在進行測試。我在加載FireBugLite JavaScript文本的服務器上放了一個頁面。它有很多JavaScript和完美的測試,看看Android WebView是否會加載它。 WebView不加載,但瀏覽器加載Firebug圖標。究竟是什麼影響了它,爲什麼它可以在瀏覽器中運行,而不是在我的WebView中運行?有什麼建議麼。Android WebView未加載JavaScript文件,但Android瀏覽器加載正常

更多的背景信息,爲了讓Droid(或除Windows之外的任何其他平臺)上可用的臭名昭着的backoffice應用程序,我需要誘騙bakcoffice應用程序相信訪問該網站的是Internet Explorer。我通過修改WebView用戶代理來完成此操作。

同樣對於這個應用程序,我縮小了我的着陸頁,所以我可以給你提供援助的來源。

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(); 
} 


} 

The background Application is my app, running in an emulator. The top application is the browser. You'll see the browser has the firebug icon, and can activate the firebug, but the application does not have the firebug icon. http://img413.imageshack.us/img413/9628/myapp.gif

我的應用程序在後臺運行,並且可以在右下角看到沒有螢火蟲。然而,瀏覽器(頂部的模擬器)具有相同的頁面,但顯示螢火蟲。我究竟做錯了什麼?我假設它沒有足夠的內存分配給應用程序,處理能力分配或物理內存。我不知道,我只知道結果很奇怪。

我得到了同樣的東西形成我的android設備,應用程序顯示沒有螢火蟲,但瀏覽器顯示螢火蟲。

我已在網絡瀏覽器上啓用JavaScript,問題是網絡瀏覽器的行爲與網絡瀏覽器不同。

+0

「我已經擁有的JavaScript上的Web瀏覽器」:

這條線是邪惡的,我想你應該將其刪除? (只是爲了確保...) – 2010-06-09 17:10:19

+0

是的,它在我的無效LoadSettings()我加載之前,它已被添加到視圖中的頁面之前調用。 – JustinKaz 2010-06-09 17:55:57

+0

不,我測試它在android瀏覽器中的工作,我需要它在我的應用程序內工作。不知何故,某些(不是大多數)Javascript沒有被加載。如果您沒有使用Android瀏覽器導航到http://kscserver.com/main-leap-slim.html FireBug是可點擊的,但是在我的應用程序中它沒有顯示,但Javascript彈出地圖仍然有效。 – JustinKaz 2010-06-10 14:59:01

回答

4

工作對我很好。我可以在WebView中看到FireBug圖標。在你的WebView的設置,這是否意味着你叫setJavaScriptEnabled(真) -

webview.getSettings().setUserAgentString(OverideUserAgent_IE); 
+0

這是此應用程序的唯一目的,它需要覆蓋用戶代理字段以顯示後臺應用程序。 「更多的背景信息,爲了讓Droid(或除Windows以外的任何其他平臺)上可用的後臺應用程序可用,我需要欺騙bakcoffice應用程序以相信訪問該網站的是Internet Explorer,我通過修改WebView用戶代理「。 – JustinKaz 2010-06-11 13:10:37

+0

所以你說什麼,因爲我正在修改用戶代理,它影響了Javascript的顯示方式?令人懷疑的是,記住我正在使用螢火蟲作爲測試,後臺有數百個JavaScript函數,根本沒有被加載。 Firebug是我不得不測試後門系統的壁櫥裏的東西。最終,我需要一種方法來覆蓋UserAgent字段,並仍然可以訪問完整的JavaScript功能。 – JustinKaz 2010-06-11 13:13:42

+2

FireBug分析用戶代理並相應地運行。如果你說你是IE FireBug以IE特有的方式做一些不適用於Android WebView的東西。你可以自己看看 - 如果你刪除了僞造的用戶代理,FireBug會以默認的方式執行這些操作,你會看到圖標。所以我擔心你必須分析你的腳本,並以IE特定的方式找到他們所做的事情。 – Fedor 2010-06-11 13:23:14