View Full Version : The document.open() and document.close() methods...
01-10-2004, 01:41 PM
I was wondering while I was making a JS HTML-editor,when the suer clicked a button the code he wrote would be written to another frame....but if I didn't use document.open() before writing anything,and then document.close() at the end.....the script would just append what the user wrote to what was already written in the page.
So,what is document.open() and document.close() real functionality?
And I thought that using document.write() after the page has finished loading will overwrite the buffer.
Where is it most indicated to use document.open() and document.close()?
01-10-2004, 05:23 PM
document.open should be used when you have a frame/window to write to, that is not already loading. It will clear a document and open a new document stream. That document stream can be written to from document.write or document.writeln. A document stream opened thus does not close unless you either make a user action that forces a closing of the stream, or use document.close to close it. As document.write will open a stream if there is no currently open stream it can write to a clean frame/window, in which case it will open the stream as if you had used document.open. The same rules for closing the stream goes. However, a document stream created by for example loading a URL to the frame/window will be closed when the entire document is loaded. That's the difference. If you want to use for example the DOM on a document that has an open stream, you should close it first, even if your specific case might not require it.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.