Javascript - Error When A Script Tag In A String
I have a page with the following code: '; This results in an error: Uncaught SyntaxError: Unexpected to
Solution 1:
the error went away when I escaped the /
with a \
.
Solution 2:
The hackish work-around for this is something like:
<script>
window.str = '<scr' + 'ipt></scri' + 'pt>';
</script>
In this way, you wind up with the string you want without confusing the parser.
Or, insert it as a DOM element if that is the ultimate goal.
Post a Comment for "Javascript - Error When A Script Tag In A String"