I'm having an issue where I'm trying to use JQuery to append a string to a div.
This string will be HTML, and occassionally users will be using the script tags inside the string.
Unfortunately, when the browser reads
Is there a way to get the browser to not parse anything inside the string?
An example of this might be an Adsense ad being appended to the div.Answer1:
You can use a backslash (
\) to escape the slash in the
<script> close tag so that it doesn't close the actual
var foo = document.write('<script src="somewhere.js"><\/script>');
This is often used when loading a script from a CDN with a local fallback:
<script src="//cdn.example.com/jquery.js"></script> <script> if (!window.jQuery) document.write('<script src="/assets/js/jquery.js"><\/script>'); </script>Answer2:
The workaround way for the problem is using:
"</scr" + "ipt>"
Ugly, annoying, but <strong>working!</strong>