4
我想在web视图中添加leadbolt横幅广告。以下是广告代码在Android中的Webview中添加Javascript
<script type="text/javascript" src="http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx"></script>
我将如何添加?
我想在web视图中添加leadbolt横幅广告。以下是广告代码在Android中的Webview中添加Javascript
<script type="text/javascript" src="http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx"></script>
我将如何添加?
WebView有一个名为loadData()的方法。允许webview直接加载html代码。您可以试试。
String js_str = "<script type='text/javascript' src='http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx'></script>"
WebView webview = new WebView();
webview.loadData(js_str, null, null);
试试这个
WebView wv = (WebView)findViewById(R.id.webViewad);
wv.getSettings().setJavaScriptEnabled(true);
StringBuilder htmlData = new StringBuilder("<html>");
htmlData.append("<head><title>Ad</title></head>");
htmlData.append("<body>");
htmlData.append("<script type=\"text/javascript\"
src=\"http://ad.leadboltads.net/show_app_ad.js?section_id=YOUR_ID\"></script>");
htmlData.append("</body>");
htmlData.append("</html>");
wv.loadData(htmlData.toString(),"text/html", "ISO 8859-1");
您可能想要逃避你的字符串中的引号。 – Eric
非常感谢!帮了我很多 –