<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*10000);
var sr = 'http://www.example.com/example.js?rnd='+randomnumber;
document.write("<script type=\"text/javascript\" src=\"" + sr + "\" id-value-test=\"100\" > </script>");
</script>
Run Code Online (Sandbox Code Playgroud)
在id-value-test获得未终止的字符串文字.任何想法?
在进行HTML解析时,浏览器不解析JavaScript,因此它们会在</script>它们找到的第一个序列处停止- 即使它是在字符串文字或JavaScript注释中.
为了避免它,只需要做任何事情来中断</script>你的字符串,例如:
<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*10000);
var sr = 'http://www.example.com/example.js?rnd='+randomnumber;
document.write("<script type=\"text/javascript\" src=\"" + sr + "\" id-value-test=\"100\" > <\/script>");
<!-- Change is here -----------------------------------------------------------------------------^ -->
</script>
Run Code Online (Sandbox Code Playgroud)
要么
<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*10000);
var sr = 'http://www.example.com/example.js?rnd='+randomnumber;
document.write("<script type=\"text/javascript\" src=\"" + sr + "\" id-value-test=\"100\" > </" + "script>");
<!-- Change is here ----------------------------------------------------------------------------^ -->
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |