我試圖在Android上工作的JavaScript此頁:JavaScript的網頁視圖不使用JavaScript啓用
http://test.swiss-impulse.com/scratch_card_game/index.html
但是我有一個關於瀏覽器的問題。
webView1.setWebChromeClient(mClient);
webView1.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
webView1.addJavascriptInterface(new JavaScriptInterfaceForTitle(this, mPasswordStrength, webView1), "HtmlViewer");
webView1.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
String cookie = CookieManager.getInstance().getCookie(url);
if (url.equals(getContentUrl() + "addcomment")) {
webView1.stopLoading();
Intent addcommentIntent = new Intent(mContext, AddCommentActivity.class);
addcommentIntent.putExtra("url", previousUrl);
startActivity(addcommentIntent);
} else {
previousUrl = url;
((BaseActivity) mContext).showLoadingDialog();
if (!urlStackList.contains(url)) {
urlStackList.add(url);
}
super.onPageStarted(view, url, favicon);
}
}
@Override
public void onPageFinished(WebView view, String url) {
((BaseActivity) mContext).hideLoadingDialog();
if (url.contains("content/shows/") || url.contains("content/tips/")) {
counter = 0;
view.loadUrl("javascript:window.HtmlViewer.showHTML(document.getElementById('" + mContext.getString(R.string.title_name) + "').innerHTML);");
view.loadUrl("javascript:window.HtmlViewer.showHTML(document.getElementById('name_en').innerHTML);");
view.loadUrl("javascript:window.HtmlViewer.showHTML(document.getElementById('name_zh').innerHTML);");
} else {
mStateBar.setShowTitle(mContext.getString(R.string.tv_drama));
}
super.onPageFinished(view, url);
}
});
webview1.setWebChromeClient(mClient);
webView1.getSettings().setJavaScriptEnabled(true);
webView1.getSettings().setPluginState(PluginState.ON);
webView1.getSettings().setPluginsEnabled(true);
webView1.getSettings().setAppCacheMaxSize(httpCacheSize);
webView1.getSettings().setSupportZoom(false);
webView1.getSettings().setBuiltInZoomControls(false);
webView1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
我失去了一些參數,使在Android的WebView這項工作:
這是爲網頁視圖設置的參數?我檢查了Chrome瀏覽器,它沒有問題,所以我肯定我錯過了一些東西,找不到什麼。
編輯:
class MyChromeClient extends WebChromeClient {
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
mCustomViewCallback = callback;
mTargetView.addView(view);
mCustomView = view;
mContentView.setVisibility(View.GONE);
mTargetView.setVisibility(View.VISIBLE);
mTargetView.bringToFront();
}
@Override
public void onHideCustomView() {
if (mCustomView == null)
return;
mCustomView.setVisibility(View.GONE);
mTargetView.removeView(mCustomView);
mCustomView = null;
mTargetView.setVisibility(View.GONE);
mCustomViewCallback.onCustomViewHidden();
mContentView.setVisibility(View.VISIBLE);
}
// For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
TvDramaActivity.this.startActivityForResult(Intent.createChooser(i, "Chooser"), 100);
}
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser(uploadMsg, "");
}
// For Android > 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
openFileChooser(uploadMsg, "");
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
}
}
public boolean inCustomView() {
return (mCustomView != null);
}
public void hideCustomView() {
mClient.onHideCustomView();
}
LogCat中是否存在任何錯誤或警告 – peshkira
添加webview1.setWebChromeClient(new WebChromeClient()); –
沒有錯誤或警告 – Tazz