1

I used this code and working but it first loads with website header and then afterward loads without header. What is wrong in this code? What to modify so that only one screen loads, i.e, without website header?

webSettings.setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webView.loadUrl("javascript:(function() { " + "var head = document.getElementsByTagName('header')[0];" + "head.parentNode.removeChild(head);" + "})()"); webView.loadUrl("javascript:(function() { " + "var head = document.getElementsByTagName('footer')[0];" + "head.parentNode.removeChild(head);" + "})()"); } }); webView.loadUrl("https://www.google.com"); 
2
  • 1
    Hope this can solve your issue. Commented Aug 8, 2020 at 7:42
  • well you could set its display none and when loaded set display block Commented Aug 8, 2020 at 9:11

1 Answer 1

0

I resolved by putting this code in OnLoadResource() method instead of OnPageFinished() and using evaluateJavascript:

override fun onLoadResource(view: WebView?, url: String?) { webView.evaluateJavascript("javascript:(function() { " + "var head = document.getElementsByTagName('footer')[0];" + "head.parentNode.removeChild(head);" + "})()", {}); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.