Rikki Tikki Tavi
Rikki Tikki Tavi

Reputation: 3139

android + javascript : create html dynamically and put javascript in the head tag

I have android application and I need to show banner in some specific manner.

I get the javascript code like this from the server :

<script type="text/javascript"
 src="http://rm.face.ua/adriver.core.2.js"></script>
  <div id="adriver_top"></div><script type="text/javascript">   
   new adriver("adriver_top", {sid: 196260, bt:52, pz:1, bn:0});
</script>

I use javascript like this :

webView.loadUrl("javascript:bannerDownload();");

so I need to put my javascript code to the javascript method and create dynamically html there and put this javascript to the head of html. I know, that is not so difficult for web-developers, but I'm deal with Java so need your help. Thank you for responses.

Upvotes: 1

Views: 1404

Answers (2)

alexbrickwedde
alexbrickwedde

Reputation: 80

With loadData, you can easily load content into the WebView.

See Android API Docs: https://developer.android.com/reference/android/webkit/WebView.html#loadData(java.lang.String,%20java.lang.String,%20java.lang.String)

And a sample at heading 5: http://www.mkyong.com/android/android-webview-example/

Upvotes: 1

Rikki Tikki Tavi
Rikki Tikki Tavi

Reputation: 3139

I solved it with the loadData. Thanks to alexbrickwedde.

But the key is to use like this:

webView.loadData(videoUrl, null, null);

Because in another cases like this :

webView.loadData(videoUrl, "text/javascript", "UTF-8");

it didn't work for me. And also don't forget enable Javascript :

webView.getSettings().setJavaScriptEnabled(true);

Upvotes: 2

Related Questions