I'm trying to show 2 webpages in WebViews. The 1st one works fine, but the 2nd will result in a blank screen.
This happens on Android 4.2.2, if I run this on a Lollipop it works fine. Moreover, I tried saving the page to the assets folder in my project and it could load properly that way.
Here are the URLs I am trying to load:
1. http://www.taiwanjobs.gov.tw/mobileApp/docDetail_frame.aspx?uid=411&pid=221&docid=141
2. http://www.taiwanjobs.gov.tw/mobileApp/docList_frame.aspx?uid=412&pid=221
Here is my code:
final WebView webView = (WebView) getView().findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.loadUrl(url);
Please help me. Thanks!
You should try this code...
I think you have to override the urlloading as below code...
webView = (WebView) view.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new webViewClient());
webView.loadUrl(url);
private class webViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
So... turns out the issue was from the webpage itself,
WebView in Android 4.2.2 just wasn't supporting it,
I tried opening it with the web browser on an Android 4.2.2 emulator,
same results.
Related
When I load a url in "Android 7.0",there are some images showing correctly but some images whose url is correct are blank in the emulator.All these images can show correctly in "Android 6.0". This is the code:
webview = new WebView(getApplicationContext());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setBlockNetworkImage(false);
webview.addJavascriptInterface(new MJavascriptInterface(this,imageUrls), "imagelistener");
webview.setWebViewClient(new MyWebViewClient());
webview.loadUrl(urlStr);
The page is implemented by jquery-fullpage plugin, like this:
http://alvarotrigo.com/fullPage/#firstPage
In android app, WebView doesn't display it properly. It overlaps all the sub pages in one page without scrollbar.
Any idea?
Version of your browser maybe affect. Check issue on Github.
Remember enable javascript in your WebView:
WebView webView = (WebView) findViewById(R.id.webview);
webView = (WebView) findViewById(R.id.webview);
webView.clearCache(true);
webView.clearHistory();
/* Enabling javascript */
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
I am now working on with the webview process, i have successfully coded to save the webview contents in my app. But, now while saving my webview content, i need to add a extra page to the existing view inside the webview. I searched quite through several links, stil i can't get an idea.
Below is my code:
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSaveFormData(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.getSettings().setSavePassword(false);
final MyJavaScriptInterface myJavaScriptInterface = new MyJavaScriptInterface(
this);
webView.addJavascriptInterface(myJavaScriptInterface, "Textview");
webView.setWebViewClient(new myWebClient());
webView.loadUrl("https://www.google.com/");
I have loaded a website with my WebView. But when I click in any link of that website , the control has been transferred from my WebView to the Android built in browser. I want to browse that site with my WebView.
I want to download book from my site. Another task that is very important to me is when I will download a book from my site ,it will give a password to my software ( android part ). What do I do to receive a password from an web site from the WebView.
This question is very important for me to complete my project.
Waiting for your replies...
The code for webView is just as following:
wv = (WebView) findViewById(R.id.mainwebview);
WebSettings ws = wv.getSettings();
ws.setBuiltInZoomControls(true);
wv.loadUrl("http://m.feedbooks.com/store");
wv.getSettings().setJavaScriptEnabled(true);
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view,String url) {
view.loadUrl(url);
return true;
}
});
wv.loadUrl(url);
above code can help you to display website with your webview
Have a look at the WebViewClient1
You can override shouldOverrideUrlLoading(WebView view, String url)
I have a problem interacting with a WebView. I'm showing an HTML login form within a WebView and I can't type inside of any of the input fields of the forms. I do can interact with the links, select boxes, buttons, etc.
Here is an example of my code. Basically I'm retrieving the web view from the xml and setting it a WebViewClient and a WebChromeClient.
webview = (WebView) findViewById(R.id.loginWebview);
webview.getSettings().setJavaScriptEnabled(true);
WebViewClient client = new WebViewClient();
webview.setWebViewClient(client);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("http://www.google.com");
Any ideas?
You can do the following to solve this:
WebView webView = (WebView)findViewById(R.id.yourWebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.requestFocus(View.FOCUS_DOWN);
There is another post here.