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.
我建议您将一个webviewClient和WebChromeClient关联到您的Web视图。
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.