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);
Related
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
I want to show a bank website application for paying online .I should use webview , this is my webview code :
WebView wb = (WebView) findViewById(R.id.webView1);
WebSettings settings = wb.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setSupportZoom(true);
settings.setJavaScriptEnabled(true);
settings.setSaveFormData(false);
settings.setSavePassword(false);
settings.setDomStorageEnabled(true);
progressBar = ProgressDialog.show(Pay.this, Z_Farsi.Convert(getString(R.string.gettingdata)), Z_Farsi.Convert(getString(R.string.wait)));
wb.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
});
The problem is , it's going to a step that I need to click on a button to connect to paying web page . I don't know why it doesn't work and button doesn't press down .
I tested it on android default browser and it worked fine .
Could you help me ? Why does that button is not working on webview?
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).
https://mobilogr.uludag.edu.tr/Login.aspx
I can't open this website in Android webview
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setSupportMultipleWindows(true);
settings.setAllowFileAccess(true);
mProgressDialog = ProgressDialog.show(this, "Uygulama Yükleniyor",
"...yükleniyor...");
mWebView.setWebViewClient(new WebViewClient() {
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}
});
mWebView.loadUrl("https://mobilogr.uludag.edu.tr/Login.aspx");
Please check whether your android Android Manifest for the Internet Permission as shown below
<uses-permission android:name="android.permission.INTERNET" />
Does your application have the permission to go on the internet?
<uses-permission android:name="android.permission.INTERNET" />
also, you want to go to this website,
but your url in your script goes to another?
I have faced the similar issue.
The easiest way is to debug and see, the page may have a broken javascript.
You need to remote debug which give you clear error in console.
Try this : https://developer.chrome.com/devtools/docs/remote-debugging
something is wrong with the certificate.
if your ssl Certificate expired or not trusted,webview will refuse to load the webpage.
To avoid this ,you should override onReceivedSslError method like this:
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error);
// ignore ssl error
handler.proceed();
}
});
i try this,everything is OK.
I have loaded an external URL in my WebView. Now what I need is that when the user clicks on the links on the page loaded, it has to work like a normal browser and open the link in the same WebView. But it's opening the default browser and loading the page there?
I have enabled JavaScript. But still it's not working. Have I forgotten something?
If you're using a WebView you'll have to intercept the clicks yourself if you don't want the default Android behaviour.
You can monitor events in a WebView using a WebViewClient. The method you want is shouldOverrideUrlLoading(). This allows you to perform your own action when a particular URL is selected.
You set the WebViewClient of your WebView using the setWebViewClient() method.
If you look at the WebView sample in the SDK there's an example which does just what you want. It's as simple as:
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
in some cases you might need an override of onLoadResource if you get a redirect which doesn't trigger the url loading method. in this case i tried the following:
#Override
public void onLoadResource(WebView view, String url)
{
if (url.equals("http://redirectexample.com"))
{
//do your own thing here
}
else
{
super.onLoadResource(view, url);
}
}
Official documentation says, click on a link in a WebView will launch application that handles URLs. You need to override this default behavior
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
or if there is no conditional logic in the method simply do this
myWebView.setWebViewClient(new WebViewClient());
Add this 2 lines in your code -
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient());
The method boolean shouldOverrideUrlLoading(WebView view, String url) was deprecated in API 24. If you are supporting new devices you should use boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request).
You can use both by doing something like this:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
newsItem.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
});
} else {
newsItem.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
Arulx Z's answer was exactly what I was looking for.
I'm writing an app with Navigation Drawer with recyclerview and webviews, for keeping the web browsing inside the app regardless of hyperlinks clicked (thus not launching the external web browser). For that it will suffice to put the following 2 lines of code:
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient());
exactly under your WebView statement.
Here's a example of my implemented WebView code:
public class WebView1 extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.wv1); //webview statement
wv.setWebViewClient(new WebViewClient()); //the lines of code added
wv.setWebChromeClient(new WebChromeClient()); //same as above
wv.loadUrl("http://www.google.com");
}}
this way, every link clicked in the website will load inside your WebView.
(Using Android Studio 1.2.2 with all SDK's updated)