Javascript - 打破字符串文字......为什么? [英] Javascript - breaking up string literals... why?
问题描述
对不起,问题标题太模糊了,但我正在查看Job posts board转换跟踪软件中的一些代码,并且第一次遇到这个问题。
I'm sorry the question title is so vague, but I was looking at some code from a Job posting boards conversion tracking software and ran across this for the first time.
document.write('<i' + 'mg height="1" ' +
'width="1" border="0" ' +
'src="' + url + '&ifr' + 'ame=0" />');
document.write('</ifr' + 'ame>');
为什么他们以这种方式分解字符串文字?具体来说,'< / ifr'+'ame>'
Why are they breaking up the string literal in this manner? Specifically '</ifr'+'ame>'
推荐答案
当HTML解析器看到某些标记时,即使嵌入在JavaScript字符串中,它们也会立即被解析为这些标记。
When HTML parsers see certain tags, even when embedded in JavaScript strings, they'll be parsed immediately as those tags.
打破它们可以避免这种行为 - < script>
通常会导致问题;我同意Mike的观点, iframe
s(AFAIK也没有其他人也没有必要,但我无法与任何权威人士谈话)。
Breaking them up avoids this behavior--<script>
is the one that usually causes problems; I agree with Mike that it shouldn't be necessary for iframe
s (AFAIK no others, either, but I can't speak to that with any authority).
这也是一种避免被抓取工具轻易解析的技巧。
It's also a trick to avoid being trivially parsed by crawlers.
这篇关于Javascript - 打破字符串文字......为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!