...

View Full Version : Document.write Problem



daled1
09-26-2011, 09: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.

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

DaveyErwin
09-26-2011, 12:42 PM
You are seeing
");

because the script ends at
</script>

and the browser thinks
");
is html
do it something like this


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

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

http://www.stevenolte.com/docwriter.html

Dormilich
09-27-2011, 08: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