动态生成的 JavaScript 无法在 Chrome 或 IE 中执行,但可以在 Firefox 中执行
我使用谷歌地图 API 和 GWT 创建一个选项卡式信息窗口,其中一个标记内包含推文。推文的来源是动态生成的。这是java代码:
HTML recentTweets = new HTML(
"<div>"+
"<script type='text/javascript' src='http://twitter.com/javascripts/blogger.js'></script>"+
"<script type='text/javascript' src='http://twitter.com/statuses/user_timeline"+twitterUser+".json?callback=twitterCallback2&count=3'></script>"+
"</div>"
);
我已经确定了问题,但我需要一个解决方法。发生的情况是,该脚本将在 Firefox 中执行,而 IE 和 Chrome 将由于某种原因避免运行它。这是生成的 html:
<div class="gwt-HTML">
<table bgcolor="#fdffd1" height="250" width="500"><tbody>
<tr>
<td align="left">
<h2><a style="color: rgb(122, 0, 69);" ;="" href="http://www.eatphamish.com" target="_blank">
<img src="http://a1.twimg.com/profile_images/334307090/autoscale-100x100_bigger.png" height="48" width="48"><font color="#7a0045">stephencolbert</font></a></h2></td></tr>
<tr>
<div id="twitter_update_list" style="color: rgb(0, 0, 0); font-size: 12px;"></div>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/stephencolbert.json?callback=twitterCallback2&count=5"></script>
</tr></tbody></div>
如果我将此代码复制到纯 html 文件中并在 google chrome 中运行它,它将起作用。如果我在 IE 中打开,它就会工作,但前提是我授予它运行活动内容的权限。如果我在 Firefox 中打开,它可以正常工作,没有任何问题。有谁知道我如何让这段代码在所有主要浏览器中无需请求许可即可工作?谢谢!
I'm using the google maps API with GWT to create a tabbed infowindow with tweets inside one of the markers. the source of the tweets is dynamically generated. heres the java code:
HTML recentTweets = new HTML(
"<div>"+
"<script type='text/javascript' src='http://twitter.com/javascripts/blogger.js'></script>"+
"<script type='text/javascript' src='http://twitter.com/statuses/user_timeline"+twitterUser+".json?callback=twitterCallback2&count=3'></script>"+
"</div>"
);
I have identified the problem, but I need a workaround. What happens is that the script will be executed in firefox, while IE and Chrome will, for some reason, avoid running it. Here is the html that is generated:
<div class="gwt-HTML">
<table bgcolor="#fdffd1" height="250" width="500"><tbody>
<tr>
<td align="left">
<h2><a style="color: rgb(122, 0, 69);" ;="" href="http://www.eatphamish.com" target="_blank">
<img src="http://a1.twimg.com/profile_images/334307090/autoscale-100x100_bigger.png" height="48" width="48"><font color="#7a0045">stephencolbert</font></a></h2></td></tr>
<tr>
<div id="twitter_update_list" style="color: rgb(0, 0, 0); font-size: 12px;"></div>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/stephencolbert.json?callback=twitterCallback2&count=5"></script>
</tr></tbody></div>
if i copy this code into a plain html file and run it in google chrome, it will work. if i open in IE, it will work, but only after i give it permission to run active content. if i open in firefox, it works fine without any problem. does anyone know how i can get this code to work without asking for permission in all the major browsers?? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦发布到远程 Web 服务器上,您生成的 HTML 就可以正常工作,而 IE 请求的权限很可能只与本地托管的文件相关。尝试在一些网站上发布,它应该适合您。
因此,这意味着发布整个 GWT 项目,因为本地测试环境可能会导致问题。
The HTML you generated worked fine once posted on a remote web server the permission IE is asking for is most likely only related to locally hosted files. Try posting on some web site and it should work fine for you.
So that would mean posting the whole GWT project because the test environment if local may be causing the problem.
我的问题的答案是 Infowindow 内容一旦设置后就是静态的。由于某种原因,Firefox 能够执行在信息窗口内运行的脚本,但无法修改其他浏览器解释这些脚本的方式。
The answer to my problem was that Infowindow content is static once it has been set. For some reason, firefox is able to execute script running inside an infowindow, but theres no way to modify how other browsers interpret those scripts.