我正在编写连接到后台办公网站的应用程序。后台网站包含一整套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();
}
}
我的应用程序在后台运行,并且可以在右下角看到没有萤火虫。然而,浏览器(顶部的模拟器)具有相同的页面,但显示萤火虫。我究竟做错了什么?我假设它没有足够的内存分配给应用程序,处理能力分配或物理内存。我不知道,我只知道结果很奇怪。
我得到了同样的东西形成我的android设备,应用程序显示没有萤火虫,但浏览器显示萤火虫。
我已在网络浏览器上启用JavaScript,问题是网络浏览器的行为与网络浏览器不同。
“我已经拥有的JavaScript上的Web浏览器”:
这条线是邪恶的,我想你应该将其删除? (只是为了确保...) – 2010-06-09 17:10:19
是的,它在我的无效LoadSettings()我加载之前,它已被添加到视图中的页面之前调用。 – JustinKaz 2010-06-09 17:55:57
不,我测试它在android浏览器中的工作,我需要它在我的应用程序内工作。不知何故,某些(不是大多数)Javascript没有被加载。如果您没有使用Android浏览器导航到http://kscserver.com/main-leap-slim.html FireBug是可点击的,但是在我的应用程序中它没有显示,但Javascript弹出地图仍然有效。 – JustinKaz 2010-06-10 14:59:01