Can't figure out how to display javascript in Android webview

限于喜欢 提交于 2020-01-15 07:21:39

问题


I have this link:

http://voap.weather.com/weather/oap/90210?template=GENXV&par=3000000007&unit=0&key=twciweatherwidget

if you copy and paste it in your browser, it acts the same as it does in my webview, it is displaying document.write(" and "); around the widget.

This is the code that that I am using in my Android app:

WebView wv = new WebView(this);

setContentView(wv);
String html = "http://xhtml.weather.com/xhtml/hbhf/90210";  

wv.loadUrl(html);

The code above displays the coded url just fine.

If I change the url to the one that I want to display (the one listed up on top), it displays the Document.Write as mentioned.

If I enable Javascript using:

    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);

and place the javascript wrapper around the url such as:

    <script type="text/javascript" src="http://voap.weather.com/weather/oap/90210?template=GENXV&par=3000000007&unit=0&key=twciweatherwidget"></script>

I notice right away that the double quotes are messing up the syntax.

I changed every double quote to " + (char) 39 + "

When I try running that code, I get a message that the url is invalid:

Here's a link to a screenshot: http://davidmcafee.org/downloads/images/AndroidWeatherErr.png

It appears that the quotes are all in the correct place.

Does anyone see what I am doing wrong? I am going nuts trying to figure out what it is.

I've searched and searched, but I am either missing something so simple, or I am searching for the wrong terms.

来源:https://stackoverflow.com/questions/8461520/cant-figure-out-how-to-display-javascript-in-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!