I have a webview that will visit a website, the problem here is that
[it didn't load the entire website content
][1]
Then I tried to use Chrome to access the website, and [it loads all the websites content][2](even though a bit messed up since it viewed in mobile).
When I tried to see the content of the missing things (things that didn't showed up in my WebView), I learned it didn't load the content that use owl-carousel,
Is there a way to let my WebView load the owl-carousel content?
P.s I have activated the javascript too
Here's the codes I create that I think lead to the problem
My Webview settings
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setBuiltInZoomControls(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
And here's my Webview procedure
public class myWebclient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
}
Progress Update
I have tried using AdvancedWebview like what Sudheesh R said, but it's still like previous condition nothing changed, it still don't load the owl-carousel content
Update #2
I̶ ̶t̶r̶i̶e̶d̶ ̶u̶s̶i̶n̶g̶ ̶m̶y̶ ̶f̶r̶i̶e̶n̶d̶ ̶W̶e̶b̶V̶i̶e̶w̶ ̶a̶p̶p̶,̶ ̶a̶n̶d̶ ̶i̶t̶ ̶l̶o̶o̶k̶s̶ ̶l̶i̶k̶e̶ ̶i̶t̶ ̶w̶o̶r̶k̶e̶d̶ ̶o̶n̶ ̶h̶i̶s̶ ̶a̶p̶p̶ ̶b̶u̶t̶ ̶I̶ ̶d̶o̶n̶'̶t̶ ̶k̶n̶o̶w̶ ̶w̶h̶y̶,̶ ̶I̶ ̶w̶i̶l̶l̶ ̶u̶p̶d̶a̶t̶e̶ ̶i̶f̶ ̶I̶ ̶f̶o̶u̶n̶d̶ ̶o̶u̶t̶ ̶h̶o̶w̶.
Alright, I have compared his code with mine, nothing seems comes to light...
Update 3
The only resource I found is this question, but as you see in my code above, I have set the Dom Storage to become enabled... Any help really appreciated
Update 4
Alright, I found out that there's a Jquery method in the website that I haven't initialize yet from my Logcat
So I initialize it but keeping it empty
#JavascriptInterface
public void getxId(){
}
[1]: https://i.stack.imgur.com/3lPNX.png
[2]: https://i.stack.imgur.com/FS6tV.png
Related
I have a custom implementation of WebViewClient that overrides onPageFinished(), where I swap my loading view with the WebView. Sometimes everything works great, but other times onPageFinished() doesn't get called at all. It's completely random.
onPageStarted() always gets called.
public class LoaderWebViewClient extends WebViewClient {
private final TableLayout swapTableLayout;
public LoaderWebViewClient(TableLayout swapTableLayout) {
this.swapTableLayout = swapTableLayout;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
// Sometimes doesn't get called
#Override
public void onPageFinished(WebView view, String url) {
swapTableLayout.removeAllViews();
swapTableLayout.addView(view);
super.onPageFinished(view, url);
}
}
I am instantiating a WebView from a custom class:
WebView webView = new WebView(context);
WebViewClient webViewClient = new LoaderWebViewClient(swapTableLayout);
webView.setWebViewClient(webViewClient);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webView.loadUrl(url);
I have found the problem. In onPageFinished() I am removing all the views from the layout inside which the WebView itself would reside (as seen in the next line).
And that somehow disrupts the loading of the WebView. I have just replaced removing and reinserting views with hiding and showing them (they are always inflated in the layout) and everything seems to work fine.
I am showing PDF files by using google docs in WebView in android.
How to remove or hide "Sign In" button? I have attached screenshot below. Thanks in advance.
webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://docs.google.com/viewer?url=http://www.ex.com/terms.pdf");
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
Add the embedded=true parameter.
webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://docs.google.com/viewer?embedded=true&url=https://orimi.com/pdf-test.pdf");
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
Note: This answer was actually proposed by user3777879. Tested, and working, he should get the credit - Stuart
Try this
I have tried to many answers but did not get good answer.
Finally got the solution with adding few code in when loading the pdf into the webview .
final WebView wv_webview= (WebView) view.findViewById(R.id.wv_webview);;
wv_webview.getSettings().setJavaScriptEnabled(true);
wv_webview.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
wv_webview.loadUrl("javascript:(function() { " +
"document.querySelector('[role=\"toolbar\"]').remove();})()");
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
wv_webview.loadUrl("javascript:(function() { " +
"document.querySelector('[role=\"toolbar\"]').remove();})()");
}
});
String your_pdf_link="https://www.antennahouse.com/XSLsample/pdf/sample-link_1.pdf";
wv_webview.loadUrl("https://docs.google.com/viewer?embedded=true&url=" + your_pdf_link);
Note:- It will show only few milliseconds when pdf loads into webview
Output:-
webview.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('drive-viewer-toolstrip')[0].style.visibility='hidden'; })()");
I'd self-host your terms document, and I'd host it as .html file format rather than .pdf.
If you do not have a domain in which to self-host the file, check other file hosting services and see if they offer a public option that won't request login. Potential services that may work for you include Mediafire, Cramitin, Hotfile, Rapidshare, etc. (this is not an ordered or comprehensive list, do your own search).
I have a webView, where I display a HTML I fetch from the backend.My problem is that I am trying to display a loading message, and show the content only after the page is done.
For doing that, I tried to use onPageFinished, which winda works, but not entirely, because it is called after the data is fetched, but BEFORE the page is displayed, so I'm still displaying a blank screen for about 1 second, before finally displaying the HTML.
From the oficial docs:
public void onPageFinished (WebView view, String url)
Added in API level 1
Notify the host application that a page has finished loading. This method is called only for main frame. When onPageFinished() is called, the rendering picture may not be updated yet. To get the notification for the new Picture, use onNewPicture(WebView, Picture).
The problem is that onNewPicture(WebView, Picture) is deprecated
So my question is, is there a way to know when the page is finished, but also fully displayed?
Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.messageId = this.getIntent().getStringExtra(ITEM_ID_KEY);
this.setUpActionBar();
this.setContentView(R.layout.activity_inbox_item_detail);
WebView view = (WebView) this.findViewById(R.id.webview);
view.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.setVisibility(View.VISIBLE);
}
});
this.fetchInboxDetailsTask(this.messageId);
}
I have a WebView in a fragment and, just for your reference, I have set it up like this.
May be you are missing something. "onPageFinished" works just fine for me.
In onViewCreated method:
mWebView = (WebView) view.findViewById(R.id.appWebView);
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;
}
#Override
public void onPageFinished(WebView view, String url)
{
webViewProgressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
});
and then:
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl("http://play.google.com/store/apps/");
You may consider using the Advanced Webview Library for android it provides an interface to reaspond to when page start loading and when finishes! here (AdvancedWebView)
I'm using a webview:
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setGeolocationEnabled(true);
webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
loading.show();
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
loading.dismiss();
super.onPageFinished(view, url);
}
});
For most links, it works just fine. But for, http://m.stubhub.com (and any of the same domain), it only shows a blank view (though it's finished loading the page). Are there settings, I'm missing or something?
Btw, there aren't any errors, as far as I can tell.
Suggestions/advice greatly appreciated. Thanks.
Did you tried onReceivedSslError ? :
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed() ;
}
Let me know if that helps !
The solution was the permissions the site required. It uses HTML5 storage, so permission for DOMStorage had to be enabled...
webView.getSettings().setDomStorageEnabled(true);
I'm having trouble resizing my WebView after loading JQuery Flot graph API.
So, here's my code:
webview.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
// view.setVisibility(View.INVISIBLE);
progressBar1.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar1.setVisibility(View.INVISIBLE);
webview.setInitialScale(100);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
}
});
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(this, "webConnector");
webview.loadUrl("file:///android_asset/graph_test_json.html");
Sometimes, the WebView is correctly displayed. The graph is fully zoommed out, so we can see it all.
Sometimes, the WebView is "too much zoomed" (a double tap on the WebView makes it zoom out correctly and the graph fits the screen).
How comes the WebView cannot be always correctly zoomed out? Is there a trick to force the WebView zooming out?
I tried to reload the page but it does not work.
I tried to apply those three lines:
webview.setInitialScale(100);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
after onResume() of the activity and it doesn't work either.
Can we programmatically zoom out a WebView?