Thanks for the response, Mike. I can't believe I didn't put those two things together!
I'm creating a page that will display a Flash Video Player (the one that comes with Dreamweaver by default) to load progressive video content. My intention is to include links on that page representing different pieces of content - when a user clicks on one of these links, it removes the existing player object and dynamically renders a new one. I thought the easiest way to do this was to put the JavaScript code that sets up the object into a separate file to be loaded in. However, this code uses document.write. I suppose I could just use jQuery to dynamically generate a DOM element and feed in the right attributes, but I thought it would be easier to just use the file Adobe gave me already. Thanks again for your response! On Sep 30, 2:41 pm, Michael Geary <m...@mg.to> wrote: > document.write() requires the document to be "open" in order to write to it. > The three related functions here are: > > document.open() > document.write() > document.close() > > When a page starts loading, the browser implicitly calls document.open() to > open the document. So document.write() works as you expect while the page is > loading. > > When the page finishes loading (roughly, around the time that jQuery's > 'ready' event fires), the browser calls document.close() to close the > document. > > After that, if you call document.write() again, the browser forces another > implicit call to document.open() first - which clears the document! That's > why you see the document.write() output replacing the entire document. > > I'm not sure off the top of my head what IE is doing differently here - it's > not executing the loaded scripts at all? Does it execute scripts if they > don't have document.write() in them? > > In any case, you can't use document.write() after the page is loaded. > > What kind of behavior are you looking for? It sounds like you do want the > scripts executed, and you want the document.write() calls to do *something* > - but what? Where should the document.write() output go? Generally, scripts > that use document.write() expect its output to be inserted into the document > immediately after the <script> tag. > > One thing you can do that may work in some cases: Replace document.write() > with a function that inserts its output into the DOM: > > function setDocumentWriteTo( selector ) { > > function write( args, end ) { > $(selector).append( > Array.prototype.join.call( args, '' ) + end > ); > } > > document.write = function() { write( arguments, '' ); }; > document.writeln = function() { write( arguments, '\n' ); }; > > } > > setDocumentWriteTo( '#writeHere' ); > > Now you can load a script that calls document.write() or document.writeln() > and it will actually call your function instead - which will append the > output to your #writeHere element. > > -Mike > > On Wed, Sep 30, 2009 at 10:22 AM, The alMIGHTY N <natle...@yahoo.com> wrote: > > > > > I need to be able to use jQuery's load function to grab the contents > > of an external file and append them to a particular DOM element. The > > problem is that when that external file includes scripts that contain > > calls to document.write, I get weird behavior that changes depending > > on which browser I'm using. > > > If I'm using Internet Explorer, the load function gets all of the non- > > script elements from the external page and correctly appends them into > > the DOM element. Of course, this is not ideal because it ignores the > > scripts. > > > If I'm using Firefox or Safari, the load function runs the scripts but > > the document.write output overrides the entirety of the calling page. > > Thus, I end up with a page that now only contains the document.write > > output instead of a page that includes the original HTML plus the > > document.write output as a child of a DOM element. > > > I don't think this is a jQuery issue but I experienced it while > > running jQuery so I posted here in the hopes that someone else has > > experienced this and knows a workaround. :-)