Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
01-10-2004, 12:41 PM #1
- Join Date
- Nov 2003
- Code Heaven
- Thanked 0 Times in 0 Posts
The document.open() and document.close() methods...
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, 04:23 PM #2
- Join Date
- Feb 2003
- Umeň, Sweden
- Thanked 83 Times in 74 Posts
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.