Tôi có Hoạt động chỉ có WebView, chứa HTML, CSS và Mã Javascript.Javascript không hoạt động trong Hoạt động webView
Dường như có một vấn đề với truy cập của Javascript với kích thước màn hình về quan điểm. LogCat nói:
(Tag: Web Console): Uncaught TypeError: Cannot call method 'getWidth' of undefined
at file:///android_asset/Prospekte/grund/html5-player/js/epaper-mobile.js:20
Khi tôi nhìn vào js-file, có: var f=this.body.getWidth();
điều có tò mò là đôi khi mã làm việc. Các ePaper được hiển thị tốt. Nhưng hầu hết thời gian có lỗi này.
setContentView(R.layout.prospekt_layout);
final Activity activity = this;
mWebView = (WebView) findViewById(R.id.prospekt_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
mWebView.loadUrl("file:///android_asset/Prospekte/modKachel/mobile.html");
Việc bố trí là:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<WebView
android:id="@+id/prospekt_webview"
android:layout_width="900px"
android:layout_height="900px"
/>
</LinearLayout>
tôi đã thay đổi kích thước của WebView vì tôi nghĩ rằng đây có thể là solution..but nó không làm việc với dp một trong hai.
Ai đó có ý tưởng?
Cảm ơn, nhưng tôi đã thử điều đó rồi. Sai lầm của tôi mà tôi đã xóa nó trong mã.Vì vậy, khi tôi thử nghiệm này, lần đầu tiên nó làm việc, lần thứ hai nó không. Có thể có vấn đề với thời gian không? Có lẽ DOM không thể được xây dựng đủ nhanh? Tôi đã thử một AsyncTask, nhưng điều đó cũng không giúp được gì. – 10ff
Cũng không thể nói bất cứ điều gì như vấn đề với thời gian hoặc vv. –
vui lòng xem cập nhật. –