Reputation: 114046
I'm inlining a large JS program, which includes a line of code like :
doc.write("<script>var app = \"" + _2d() + "\";</script>");
Unfortunately the browser (chrome) thinks the script in the string is the closing script tag, and actually takes everything after that like its HTML text.
How do I include such a string and escape it so it does not confuse the browser HTML parsing?
Upvotes: 9
Views: 5937
Reputation: 114046
I solved it by splitting the script tag like this SO question recommends:
doc.write("<scr"+"ipt>var app = \"" + _2d() + "\";</scr"+"ipt>");
Upvotes: 4
Reputation: 324730
You should always use <\/script>
if you want to put </script>
in a string in JS, because </script>
marks the end of the tag no matter where it shows up.
Upvotes: 23