Javascript 代码,包含 javascript 的未终止字符串文字
该脚本工作正常,除非包含的文件包含 javascript,否则它会因“未终止的字符串”文字错误而中断。删除空格和换行符并不能解决问题。
<script type="text/javascript">
var myArray = [
'url',
'url2',
'url3',
'url4',
'url5',
];
var i, numDomains = myArray.length, found = false;
for (i = 0; i < numDomains; i++) {
if (document.referrer.indexOf(myArray[i]) > -1) {
found = true;
}
}
document.write((found ? '<?php include("file1.php"); ?>' : '<?php include("file2.php"); ?>'));
</script>
一个好的解决方案是包含的文件可以是任何普通的 html 文件。
这是有问题的文件的输出:
<!-- google_ad_client = "pub-0705348955426556";/* ORG 468x60 */ google_ad_slot = "2106718798";google_ad_width = 468;google_ad_height = 60;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><script src="http://googleads.g.doubleclick.net/pagead/test_domain.js"></scri
This script works fine, unless the included file contains javascript, then it breaks with the "unterminated string" literal error. Removing spaces and linebreaks does not cure the problem.
<script type="text/javascript">
var myArray = [
'url',
'url2',
'url3',
'url4',
'url5',
];
var i, numDomains = myArray.length, found = false;
for (i = 0; i < numDomains; i++) {
if (document.referrer.indexOf(myArray[i]) > -1) {
found = true;
}
}
document.write((found ? '<?php include("file1.php"); ?>' : '<?php include("file2.php"); ?>'));
</script>
A good solution would be where the included file can be any normal html file.
This is the output of the offending file:
<!-- google_ad_client = "pub-0705348955426556";/* ORG 468x60 */ google_ad_slot = "2106718798";google_ad_width = 468;google_ad_height = 60;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><script src="http://googleads.g.doubleclick.net/pagead/test_domain.js"></scri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果
file1.php
或file2.php
输出任何带有未转义的'
字符或换行符的内容,这将导致您收到消息。尝试从有问题的文件中删除所有换行符,其输出如下所示:
If
file1.php
orfile2.php
output anything with un-escaped'
characters or line breaks, this would cause the message you're getting.Try removing all line breaks from the offending file, its output looks like this:
删除该行的最后一个逗号:
Remove last comma from this line:
如果包含文件中有换行符,则会导致错误。例如:
If there are line breaks in the include files, that causes error. For example: