在Android的Webview中添加Javascript

在Android的Webview中添加Javascript,javascript,android,Javascript,Android,我想在网络视图中添加leadbolt横幅广告。下面是广告代码 <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='te

我想在网络视图中添加leadbolt横幅广告。下面是广告代码

<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);
String js_str=“”
WebView 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");
WebView wv=(WebView)findviewbyd(R.id.webViewad);
wv.getSettings().setJavaScriptEnabled(true);
StringBuilder htmlData=新的StringBuilder(“”);
htmlData.append(“Ad”);
htmlData.append(“”);
htmlData.append(“”);
htmlData.append(“”);
htmlData.append(“”);
加载数据(htmlData.toString(),“text/html”,“ISO 8859-1”);

您可能希望转义字符串中的引号。