The problem may be that the web browser sees the sequence " </script> " and decides that the end of the script block.
Another way to fix the problem, besides using the escape sequence, as you did, is to break it into two lines that are combined:
"<" + "/script>"
The behavior you see is not a bug in the browser part.
Browsers do not "peek" into the script block, they simply pass the contents to the script engine. The sequence " </script> " is how they know that they have come to the end of the block, and since the browser does not interpret the contents of the block, it has no way of knowing that this is in the context of the string literal in the script code.
Remember that browsers can support more script languages ββthan just Javascript, even if this is not often observed. Internet Explorer supports VBscript (and I think that any scripting language that can be run by a Windows script host, but I'm not sure about that). And when the ability to have script blocks was put back in browsers, when no one could be sure that Javascript would turn out so universal.
Michael burr
source share