Why do some sites (or advertisers that give clients javascript code) employ a technique of splitting the <script> and/or </script> tags up within document.write() calls?
I noticed that Amazon does this as well, for example:
<script type='text/javascript'> if (typeof window['jQuery'] == 'undefined') document.write('<scr'+'ipt type='text/javascript' src='http://z-ecx.images-amazon.com/images/G/01/javascripts/lib/jquery/jquery-1.2.6.pack._V265113567_.js'></sc'+'ript>'); </script>
</script>has to be broken up because otherwise it would end the enclosing<script></script>block too early. Really it should be split between the<and the/, because a script block is supposed (according to SGML) to be terminated by any end-tag open (ETAGO) sequence (i.e.</):However in practice browsers only end parsing a CDATA script block on an actual
</script>close-tag.In XHTML there is no such special handling for script blocks, so any
<(or&) character inside them must be&escaped;like in any other element. However then browsers that are parsing XHTML as old-school HTML will get confused. There are workarounds involving CDATA blocks, but it’s easiest simply to avoid using these characters unescaped. A better way of writing a script element from script that works on either type of parser would be: