Reputation: 9583
I doubt the last option, but probably one of the first two. Can anybody tell me which?
I'm getting the error in the screen shot.
<html>
<head>
<script type="text/javascript">
var html = "<script></script>";
</script>
</head>
<body>
</body>
</html>
Upvotes: 1
Views: 143
Reputation: 9691
You can also use \ to render that character correctly:
var html = "<script><\/script>";
Upvotes: 2
Reputation: 26740
That's no bug. It's the correct behaviour for a script tag, what you're doing is the equivalent of not escaping a quote in a string.
var string = 'My mother's awesome.';
An easy way to fix your issue is to break apart the </script>
tag, like so:
var html = "<script></"+"script>";
Upvotes: 1
Reputation: 4368
This is a problem in every browser, the script block is terminated at the first string </script>
, so if that string appears in your code anywhere it will cause a premature termination of the script block.
If you want to have this as a variable in JS, use:
var html = unescape("%3Cscript%3E%3C/script%3E");
Upvotes: 5