LABjs 加载脚本时出现问题
我正在使用 labjs 来加载我的脚本。我有一个来自 feedburner 的脚本,它显示我博客中来自 rss feed 的 HTML 最新帖子。 feedburner 中的代码运行良好,以 html 形式显示所有帖子:
<script src="http://feeds.feedburner.com/Goonerhood?format=sigpro" type="text/javascript" ></script>
我正在尝试使用 labjs 加载相同的脚本,但它没有显示任何内容。这是我的代码:
<script>
$LAB
.script("http://feeds.feedburner.com/Goonerhood?format=sigpro");
</script>
有什么建议我哪里出错了吗?
I'm using labjs to load my scripts. I've got a script from feedburner which shows the lastest posts from my blog in HTML from my rss feed. The code from feedburner is and works just fine, showing all the posts in html:
<script src="http://feeds.feedburner.com/Goonerhood?format=sigpro" type="text/javascript" ></script>
I'm trying to load the same script using labjs, but it's not showing anything. Here's my code:
<script>
$LAB
.script("http://feeds.feedburner.com/Goonerhood?format=sigpro");
</script>
Any suggestion where I'm going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是该脚本全部与
document.write
相关,当您使用任何类型的动态异步技术加载脚本时,无法使用(好吧,不应该使用)它。当使用
标记导入脚本时,可以使用
document.write
函数,原因有两个:document.write
将内容附加到正在进行的 DOM。当异步加载脚本时,只有在 DOM 完成之后才会执行脚本。此时,对
document.write
的调用会隐式调用document.open
,这在已构建的页面上会破坏所有内容。The problem is that that script is all about
document.write
, which cannot be used (well, should not be used) when you're loading a script with any sort of dynamic, asynchronous technique.The
document.write
function can be used when a script is imported with a<script>
tag for two reasons:document.write
appends content to the in-progress DOM.When you load a script asynchronously, the script won't be executed until after the DOM is completed. At that point, a call to
document.write
implicitly callsdocument.open
, which on an already-built page will blow everything away.