Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2003
    Location
    Code Heaven
    Posts
    129
    Thanks
    0
    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()?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •