View Full Version : Document.write Problem

09-26-2011, 08:18 AM
document.write("<script type='text/javascript' src='http://www.website.com/javscript.js'></script>");

For some reason this will not output correctly. It ouputs


Which is the last three characters.

09-26-2011, 09:01 AM
I figured it out. I need to escape the forward slashes

09-26-2011, 11:42 AM
You are seeing

because the script ends at

and the browser thinks
is html
do it something like this

document.write("<script type='text/javascript' src='javscript.js'></"+"script>");

09-26-2011, 01:52 PM
I often use this site for such purposes:


09-27-2011, 07:34 AM
I wouldn’t use document.write() in this case at all. just put the <script> tag in the HTML. if JavaScript is enabled, the script file is used, if not (which should be quite a low percentage of users), then it’s not used.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum