2

I'm trying to open a .html page that uses javascript in a WebView. To be explicit, I'm trying to open the demo-eBook by 1000°-ePaper.

I copied the demo-folder into my asset-folder, so there is a file called "mobile.html". This HTML-file uses some javascript and .css. It seems that it is trying to open a "mobile.html#/page/0" first.

When I load the WebView, it says: "Please activate Javascript".

My Code:

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

mWebView.loadUrl("file:///android_asset/Prospect/test/mobile.html");

So it should work, right? The confusing thing is that I can load the mobile.html, when I put all the stuff online an use the defaultBrowser.

2
  • 1
    Just wondering is the "Please Activate JavaScript" message from the WebView class or is it from the HTML/JavaScript? I haven't seen it before and I have used embedded HTML and JavaScript a few times. Generally it just works with WebView.getSettings().setJavaScriptEnabled(true); so I'd imagine it's just something small going wrong somewhere. Even of your not using them I think it helps to throw in clients too e.g WebView.setWebChromeClient(new WebChromeClient()); Commented Dec 19, 2011 at 10:25
  • It's a message from the HTML/JavaScript. Ok, nice to hear that it should be something small. Commented Dec 19, 2011 at 10:28

2 Answers 2

1

I'll suggest you to associate a webviewClient and WebChromeClient to your web view.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, I did it like in this tutorial, but it didn't help: giantflyingsaucer.com/blog/?p=1331 I think, that the WebChromeClient just helps to show the Progress and the Webviewclient overrides the default Browser? Or have I done it in the wrong way?
You are absolutely correct about WebViewClient where as WebChromeClient is responsible for handling Javascript messages and processes.
0
 public class ViewWeb extends Activity {           
     @Override         
     public void onCreate(Bundle savedInstanceState) {         

     super.onCreate(savedInstanceState);     
     setContentView(R.layout.webview);           
     WebView mWebView;            
     mWebView = (WebView) findViewById(R.id.webView1);        
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.getSettings().setSavePassword(false);    
     mWebView.getSettings().setSaveFormData(false); 
     mWebView.loadUrl("file:///android_asset/myfile.html");     
     mWebView.setWebViewClient(new MyWebViewClient()); 

 private class MyWebViewClient extends WebViewClient  {   
     @Override     
     //show the web page in webview but not in web browser   
     public boolean shouldOverrideUrlLoading(WebView view, String url) {      
         view.loadUrl (url);      
         return true;
     } 
 }
 mWebView.loadData("", "text/html", "utf-8"); 

4 Comments

I tried that and copied the text of the HTML-file here: mWebView.loadData("HERE I copied the text of the mobile.html", "text/html", "utf-8"); Was that your thought? Unfortunately it's just showing the clear html text and ignores css/javascript code that are linked and in separate files, so I don't have Inline Code
Is the "myfile.html" in your case just a helpfile to open the webClient?
Have you tried putting in some of the stuff (JS, CSS) Inline just to see if it works? Maybe there is a linking issue?
Didn't try this till now, because the .js-code is too much. To be explicit, it's a ePaper-HTML-document that I buyed. It seems that the DOM isn't built fast enough, cause 1 out of 15 times the content is shown very well. Is it possible to spend the DOM enough time to be built? LogCat says: couldn't execute method getWidth() of undefined'. In the .js-file, there is: this.body.getWidth() .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.