0

I have this WebView and I want to open this script in it. How do I do this?

WebView webview = (WebView) findViewById(R.id.webView1);
   webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("javascript:<script>http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx</script>")

Here is the script:

<script type="text/javascript" src="http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxx"></script> 

2 Answers 2

1

Try like this, I haven't tested it so might have minor errors. But it should give you the idea:

webview.getSettings().setJavaScriptEnabled(true);  
webview.setWebViewClient(new WebViewClient() {  
  @Override  
  public void onPageFinished(WebView view, String url){
    webview.loadUrl("javascript:(function() { " +  
    "var script=document.createElement('script');" +
    "script.type='text/javascript';" + 
    "script.src='http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxx';" +
    "document.getElementsByTagName('head').item(0).appendChild(script);"+  
    "})");  
  }  
});  
webview.loadUrl("http://www.google.com");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the response. I have found a correct answer myself.
0

Here is the solution:

 WebView webview = (WebView) findViewById(R.id.webView1);
    webview.setVisibility(View.VISIBLE);
    webview.bringToFront();
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setBackgroundColor(Color.TRANSPARENT);
    String html = "<script type='text/javascript' src='http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxx'></script>";
    webview.loadData(html, "text/html", "utf-8");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.