0

I want to integrate an existing website into my webview but also override a javascript function that exists on this website with my own version? Then I can use the java-javascript bridge. I have tried using the following but it seems to execute the function only

webView.setWebViewClient(new WebViewClient() {
  @Override
  public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    webView.loadUrl("javascript: (function myFunc() { "
        + "alert('overriden alert ha!');"
        + "})()");
  }
});
user1159819
  • 1,549
  • 4
  • 16
  • 29

1 Answers1

1

You need

  1. grab html page source
  2. Edit it. (add into html source you grabbed, easy way : replace("<head>","<head>"+"your code");
  3. load edited String of HTML using webview.loadDataWithBaseURL("", string, "text/html", "utf-8", "");
Community
  • 1
  • 1
HelmiB
  • 12,303
  • 5
  • 41
  • 68