2012-09-04 38 views

回答

3

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

您可能想要逃避你的字符串中的引号。 – Eric

+0

非常感谢!帮了我很多 –

0

试试这个

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