To make changes to the webpage, webView needs to be enabled to execute Javascript.
This is done by the API setJavaScriptEnabled()
which accepts a boolean parameter. True for enabling javascript execution.
To remove the header and footer, the ids of the same are needed. That can be obtained by checking the JS file of the webpage.
Say the id for header is page_header
and that of footer is page_footer
.
Assign a string variable to the script javascript:document.getElementById('page_header').remove();
This will find the id in that web page and remove it due to the remove()
method.
We then just need to execute the above script.
webview.evaluateJavaScript()
helps us do that. The parameters required are the script and callback. The callback can be null if none is needed.
Hence to remove the header,
`String removeHeader = "javascript:document.getElementById('page_header').remove();";
if (Build.VERSION.SDK_INT >= 19) {
webView.evaluateJavascript(script, callback);
} else
webView.loadUrl(script, null);`
12
solved Remove header and footer in android studio webview [closed]