Inject JavaScript into Android WebView

webview.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webView.loadUrl(
"javascript:(function() { " +
"var element = document.getElementById('hplogo');"
+ "element.parentNode.removeChild(element);" +
"})()");
}
});
Demo: removing the middle image through javascript injection

--

--

--

[Android Developer 💻] [Japan addicted🇯🇵] [Music enthusiast 🎵🎶][Traveler 🛩 and coffee ☕ person]

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Filipe Batista

Filipe Batista

[Android Developer 💻] [Japan addicted🇯🇵] [Music enthusiast 🎵🎶][Traveler 🛩 and coffee ☕ person]

More from Medium

Android Tutorial: UI Components

Understanding Clean Architecture in Android Development

Kotlin: Scope Functions

Kotlin vs Java - Key Differences: Which One is Better for Android App Development