这意味着什么:" document.write('< scr'+'ipt ...&quot ;? [英] What does this mean: "document.write('<scr'+'ipt... "?

查看:259
本文介绍了这意味着什么:" document.write('< scr'+'ipt ...&quot ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在每个雅虎上都看到了这一点。
源代码底部的新闻页面
,但不明白他们为什么会破坏脚本这样的词。


有谁知道是否有任何理由为此?

  document.write(< scr+ipt language = javascript src = http:// l。 yimg.com/d/lib/bc/bc_2.0.4.js></scr\"+\"ipt>); 


解决方案

考虑这个简化的例子:

 < script> 
document.write(something< / script> something);
< / script>

浏览器的HTML解析器会看到< / script> ,并将其解释为脚本元素的结尾。



HTML解析器不知道JavaScript语法 - 它只知道< script> 元素在下一个< / script> 结束。



(它也知道你不能嵌套< script> 元素,因此打开< ;脚本> 以及在你的例子中关闭的< / script> 。)


I've seen this on every Yahoo! news page, at the bottom of the source code,
and failed to understand why they break the script word like that.

Does anybody know if there's any reason for this?

document.write("<scr"+"ipt language=javascript src=http://l.yimg.com/d/lib/bc/bc_2.0.4.js></scr"+"ipt>");

解决方案

Consider this simplified example:

<script>
document.write("something </script> something");
</script>

The browser's HTML parser would see the </script> within the JavaScript string and interpret that as the end of the script element.

The HTML parser doesn't know about JavaScript syntax - all it knows is that the <script> element ends at the next </script>.

(It also knows that you can't have nested <script> elements, hence the breaking of the opening <script> as well as the closing </script> in your example.)

这篇关于这意味着什么:&quot; document.write('&lt; scr'+'ipt ...&quot ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆