0

Is it possible to inject a javascript file (located in the asset folder) to be included every time a page is loaded in android webview.

Android version: ICS 4.0.3

immagonnagetya
  • 101
  • 1
  • 1
  • 7

1 Answers1

0

Yes, you can do this:

webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("javascript:(alert())");

EMODE
  • 9
  • 2
  • Thanks EMODE but this does not answer my question. – immagonnagetya Feb 28 '14 at 07:10
  • You can read the JS and load it as html webView.loadDataWithBaseURL("file:///android_asset/", htmlStr, "text/html", "UTF-8", null); Answer is here: http://stackoverflow.com/questions/6533207/android-webview-load-local-javascript – EMODE Feb 28 '14 at 07:16
  • Do you know exactly what this means? "Read the html into a string (htmlStr)" – immagonnagetya Feb 28 '14 at 07:22
  • Loads the given data into this WebView, using baseUrl as the base URL for the content. http://stackoverflow.com/questions/9414312/android-webview-javascript-from-assets – EMODE Feb 28 '14 at 07:27
  • Answer 2 has enough detail to get you going – EMODE Feb 28 '14 at 07:27