简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM