Because it is considered as:
<script>
alert('
</script>
');
which is a SyntaxError
You can use
alert( '<\/script>\n');
문제
I have a simple javascript (jsFiddle):
alert('</script>');
Browser fails to understand it.
This is console output:
Uncaught SyntaxError: Unexpected token ILLEGAL
But this script works (jsFiddle):
alert('</scriptt>');//shows alert text '</scriptt>'
Is it some kind of browser bug or normal ECMAScript
behaviour?
(browser is Chrome)
해결책
Because it is considered as:
<script>
alert('
</script>
');
which is a SyntaxError
You can use
alert( '<\/script>\n');
다른 팁
The HTML parser does not understand JavaScript und thus looks for something which closes the tag which is </script>
. If you need '</script>'
as string in JavaScript simply use '</s'+'cript>'
.
JavaScript isself does not have such a problem, using var x = '</script>';
in nodejs is no problem. The HTML parser is.
This is Javascript embedded in HTML script tags, right?
Then the HTML parser terminates your script in the middle.
Put the Javascript into its own file or break up the string literal. Maybe a CDATA section also works.