PDA

View Full Version : nested doument.write


firefly-david
07-03-2007, 12:55 PM
Hello,

I have a weird problem that can't seem to find a simple solution. I need to create a js file that output our global navigation bar which will be included on our 3rd party websites - cause everytime we update out nav we have to email our partners the new nav. So I would like to have the nav on our servers and the partner sites will just have the script tag on their pages.

So I created a js file that document.write the html for the bar. Within this html there is a script src that does a document.write for our advertisement tag. The problem is the nested doc.write gets outputted after the nav bar. This only happens in IE it works fine in FF and Safari.

Example:

test.html:
<script src="1.js" type="text/javascript" charset="utf-8"></script>

1.js:
document.write('start <script src="2.js" type="text/javascript" charset="utf-8"></script> end');

2.js:
document.write("middle")


In FF and Safari it outputs
"start middle end"

In IE it outputs:\
start endmiddle


I must be missing something but I can't figure it out.
Thanks

RysChwith
07-03-2007, 01:24 PM
I'm kind of surprised that works in Firefox and Safari. I suspect you'll have to abandon the document.write statements to get it to work reliably; you'll need to create the nav using DOM methods instead.

Before you go into that, though, I feel I must at least attempt to convince you that this is the wrong way to go about this.

Never, ever make a page that relies on JavaScript for basic functionality. Something like 5 to 10% of all browsers have JavaScript disabled, and most people with visual impairments or browsing on alternative devices (cell phones, PDAs, etc.) don't have JavaScript capabilities.

I'd recommend looking into server-side includes as an alternative.

Rys