admin管理员组文章数量:1289986
Here's the entire document that causes the error in Firefox and Chrome:
<!DOCTYPE html>
<html>
<head>
<script>
var strs = [], scripts = ['harbl.js'], s = 0;
strs.push('<script src="' + scripts[s] + '"></script>');
</script>
</head>
<body>
<p>buh...</p>
</body>
</html>
/
The error I get is:
Uncaught SyntaxError: Unexpected token ILLEGAL
This has me really puzzled.
Here's the entire document that causes the error in Firefox and Chrome:
<!DOCTYPE html>
<html>
<head>
<script>
var strs = [], scripts = ['harbl.js'], s = 0;
strs.push('<script src="' + scripts[s] + '"></script>');
</script>
</head>
<body>
<p>buh...</p>
</body>
</html>
http://jsfiddle/cryptoquick/J4zZT/
The error I get is:
Uncaught SyntaxError: Unexpected token ILLEGAL
This has me really puzzled.
Share Improve this question asked Oct 1, 2012 at 18:38 Hunter BeastHunter Beast 7817 silver badges18 bronze badges 1- @Sednus what is the point of that? – Ian Commented Oct 2, 2012 at 3:25
3 Answers
Reset to default 9The </script>
literal is parsed by the browser as it's not aware of the context when traversing your code. You have to escape it like so : <\/script>
. It's a known problem.
Change it to:
strs.push('<script src="' + scripts[s] + '"></s' + 'cript>');
Front Slash '/'
is considered as special character . It's the cause for the error .
strs.push('<script src="' + scripts[s] + '"><\/script>');
Please read this post for more information JavaScript and forward slashes in strings .
本文标签:
版权声明:本文标题:javascript - String literal causes "Unexpected token ILLEGAL" in Chrome, Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741407787a2377049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论