1

I've been reading a bit about injecting a script into an HTML file, mostly here

But I also came across this variation of using the document.write method.

document.write('<scr'+'ipt type="text/javascript" src="' + url + '"></scr'+'ipt>');

What could the advantage be to splitting the <script part of the <script> tag up like <scr'+'ipt?

Community
  • 1
  • 1
1252748
  • 14,597
  • 32
  • 109
  • 229

1 Answers1

5

There aren't any. It is just cargo-culting.

There are problems with having the sequence </script> as data inside a <script> element (since it will act as an end tag and terminate that script element). That, however, is best dealt with by an escape rather then a concatenation: "<\/script>". (Best is slightly subjective, but it is shorter, uses fewer operations and is (IMO) more readable).

The concatenation is a valid alternative to it, and some people have misunderstood the need and applied it to start tags as well as end tags, and then other people have just copy/pasted the results. Hence: cargo cult.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335