Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  178] [ 5]  / answers: 1 / hits: 19769  / 13 Years ago, tue, january 3, 2012, 12:00:00

I have an Activity that has just a WebView, which contains HTML, CSS and Javascript Code.



It seems that there's a problem with the access of Javascript to the screen size of the view.
LogCat says:



(Tag: Web Console): Uncaught TypeError: Cannot call method 'getWidth' of undefined 
at file:///android_asset/Prospekte/grund/html5-player/js/epaper-mobile.js:20


When I look into the js-file, there is: var f=this.body.getWidth();



There curious thing is that sometimes the code works. The epaper is shown well. But most time there's this error.



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


The layout is:



 <?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>


I changed the size of the webView cause I thought that this could be the solution..but it's no working with dp either.



Someone has in idea?


More From » android

 Answers
7

Set this setting as well for your webView:



WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);


For Detail refer to answer in the following link:
ERROR/Web Console: Uncaught TypeError: Cannot call method 'getItem' of null at http://m.youtube.com/:844



Update:
or adding this might help:



webView.loadDataWithBaseURL(fake://fake.com, myString, text/html, UTF-8, null);

[#88263] Sunday, January 1, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
frederickmohamedw questions
Wed, Sep 23, 20, 00:00, 4 Years ago
Sat, Jul 18, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Sat, Jan 11, 20, 00:00, 4 Years ago
Fri, Dec 27, 19, 00:00, 4 Years ago
;