Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this script element broken up into multiple document.write() calls? [duplicate]

Tags:

javascript

Possible Duplicate:
Why split the <script> tag when writing it with document.write()?

I have frequently seen the following statement:

document.write("<scr");
document.write("ipt language=\"Javascript\" type=\"text/javascript\" src=\"source url\"></scr");
document.write("ipt>");

What is the advantage of this? Why don't people write the whole script, as below?

document.write("<script ");
like image 891
developer Avatar asked Dec 18 '25 08:12

developer


1 Answers

This might help you:

http://www.webmasterworld.com/forum91/2913.htm

Depending on the browser, the amount of other preceding javascript, and how well-formed the overall code is, this is done to prevent the parser from interpreting the and tags as executeable code rather than as a string to be written.

I have found that it just saves headaches down the road if you do this when using script to write script tags.

like image 173
James Wiseman Avatar answered Dec 20 '25 21:12

James Wiseman