jhhayashi jhhayashi - 5 months ago 12
HTML Question

Browser interpreting Javascript string as HTML tag

I have the following in my source HTML:

<head>
...
<script>window.jQuery || document.write('<script src="/js/jquery.min.js"></script>');</script>
...
</head>


But it is getting interpreted by my browser (Chrome) as:

<head>
...
<script>window.jQuery || document.write('<script src="/js/jquery.min.js"></script>
</head>
<body>
"');"
...


I've tried escaping the slash inside the
document.write
string, but that didn't work. Does anyone know how to prevent the browser from interpreting it as as a closing script tag?

Answer

</script> is alwasy interpreted as closing script tag even if it's inside string you need to split it like this:

'</'+'script>';
Comments