I am using Android WebView to load some web pages. I need insert a piece of Javascript code to all the pages before they loaded.
I am trying to inject them on WebViewClient onPageStart callback.
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loadUrl("javascript:var output='test string';");
}
})
mWebView.loadUrl("xxx.html");
HTML code:
<html>
<script>document.write(output);</script>
</html>
I expected My Js code loaded before HTML. But sometimes the JS code loaded after HTML.
Is there any way could solve my issue?