I'd like to set top padding in a html source using JS function.The point is to not reload the page when this function will take effect, that's why I supposed to use innerHTML property.
My actual source is:
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView web, String url) {
web.loadUrl("javascript:(function(){document.body.innerHTML = document.body.innerHTML.style.paddingTop = 100px");
}
});
this solution is not working, giving me warning:
I/chromium: [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
You need to write
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView web, String url) {
web.loadUrl("javascript:(function(){ document.body.style.paddingTop = '100px'})();");
}
});
Related
When creating an application i noticed it is not recognized as the variable navigator.standalone is not set. I first thought i would fix this bij setting it mannually when injecting javascript as below:
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
webView.evaluateJavascript("navigator.standalone = true;", new ValueCallback<String>() {
#Override
public void onReceiveValue(String s) {
Log.e(TAG + "jsinject", s);
}
});
}
});
webView.addJavascriptInterface(new WebAppInterface(this, webView), "Android");
However this injects to late and some javascript functions wont fire because it is not recognized as a standalone application. Is there a possibility to set the var before the page finished loading?
I replaces the function onPageFinished(WebView view, String url) with onPageStarted(WebView view, String url, Bitmap favicon) this injects the navigator var before the page is fully loaded
I have been able to successfully remove a part of a webpage using the below code, but the only problem is that the webview first display the complete webpage and then it removes the element 'header-text-nav-container' although I am calling it onPageFinished(). I tried many different ways but all in vain. How to display the webpage in the webview only after successfully removing the element 'some-part' in my case 'header-text-nav-container'. Please help
public class myWebClient extends WebViewClient
{
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
view.loadUrl("javascript:(function() { " +
"document.getElementById('header-text-nav-container').style.display='none'; " +
"})()");
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
}
I finally solved the problem by showing a progress dialog and then dismissing the progress dialog when the 'header' is successfully removed. Thus I solved the problem partially.
isssue in Webview
I load pdf files using this url inside a webview " http://staging-argo.ephronsystems.com/content.php?type=view&docType=category&fileId=49&menuID=44"
in this page contains touch jquery plugin.
Thanks for help
You can use original pdf file http://staging-argo.ephronsystems.com/admin/uploads/category_files/ARGO BOND REQUEST FORM.pdf
and for viewing purpose you can use Google Docs Viewer
https://docs.google.com/viewer?url=http://staging-argo.ephronsystems.com/admin/uploads/category_files/ARGO BOND REQUEST FORM.pdf
try this.
web=(WebView)findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setPluginState(WebSettings.PluginState.ON);
web.getSettings().setAllowFileAccess(true);
web.getSettings().setSupportZoom(false);
web.setWebViewClient(new WebViewClient());
loadUrl();
And loadUrl() ->
#JavascriptInterface
public void loadUrl() {
web.post(new Runnable() {
#Override
public void run() {
web.loadUrl(url);
}
});
}
And this.
private class WebViewClient extends android.webkit.WebViewClient
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
return true;
}
}
I am trying to display a webpage using webView. I use loadDataWithBaseUrl to display the webpage.
webView = (WebView) findViewById(R.id.webview);
WebSettings settings=webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
(activity).setTitle("Loading...");
(activity).setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
}
});
String s= "file://"+f.getAbsolutePath()+"/";
webView.loadDataWithBaseURL(BASE_URL,HTMLData, "text/html", "utf-8","");
The problem I am facing is that the javascript on the page which should have been called on onLoad is not being run. The browser displays the webpage correctly. Also, the loadUrl method gives the correct results. Please suggest a possible solution.
Edit: I got it sorted out. The javascript file had an error. Please ignore.
I would like to know if there is a way to detect if the page is loaded completely in a webview - and if not loaded completely, automatically reload it again until the page is loaded entirely.
Is there a way to detect it ?
Thank you.
there is no definitive way to tell if the page will not finish loading. Still you can achieve similar kind of functionality by implementing WebViewClient.Timer t= new Timer("pageloadtimer", true);
webView.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url) {
t.cancel();
}
}
public void loadURL(String url, long timeout){
t.schedule(new TimerTask(){
public void run(){
webview.reload();
}
}, timeout);
webview.load(url);
}
prateek i think this will work for u.......
in your webview set webview client as follows....
wv.setWebViewClient(new WebViewClient(){
});
and use webViewclients different callback methods to detect page loade or not or did u recieve some error while loading etc......
some of its methods are
public void onPageStarted(WebView view, String url,Bitmap favicon) {}
public void onPageFinished(WebView view, String url) {}
public void onLoadResource(WebView view, String url) {}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {};
look for these methods.....
Thanks.