Results 1 to 7 of 7

Thread: Help regarding document.clear()

  1. #1
    Join Date
    Oct 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help regarding document.clear()

    I'm using document.write() function to write onto the document body. But after writing some text, I want to clear the document. Let us say if you click on a button, text on the document will be erased. For this I tried to use document.clear() method. But it doesn't seem to be working. What can I do?

    Thanks in advance.

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    To clear the body tag, but not the head tag:
    Code:
    document.documentElement.replaceChild(document.createElement("body"), document.body);
    To clear everything:
    Code:
    document.replaceChild(document.createElement("html"), document.documentElement);
    One that works with XML as well:
    Code:
    document.replaceChild(document.createElement(document.documentElement.tagName), document.documentElement);
    Last edited by Trinithis; 10-03-2007 at 05:10 AM.
    Trinithis

  3. #3
    Join Date
    Oct 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I have to clear text in a Frame.

    I want to clear text in a frame. For this I tried parent.frames[1].document.replaceChild(document.createElement("html"), document.documentElement);

    But this is not working.

    Actually, what I am doing is I'm placing a menu on left side (This is frame 0). And there is another page on right side of the page (This is frame 1). That "frame 1" contains a horizontal CSS based menu. What I want to do is, When I Click on any one of the menu on the left side frame, content on the right side frame has to change. When I click on the left side menu, then it is displaying page on the right side frame. I'm writing response using document.write() method. But if I click on the left menu again, it is appending current response with previous one. So, if the user clicks on the left menu, right side frames contents has to be erased. What should I have to do?

  4. #4
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    I forget how to use frames very well, but try this:
    Code:
    var f = window.parent.frames[1].document;
    //or is it... var f = window.frames[1].document;
    f.replaceChild(f.createElement("html"), f.documentElement);
    Trinithis

  5. #5
    Join Date
    Oct 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Trinithis View Post
    I forget how to use frames very well, but try this:
    Code:
    var f = window.parent.frames[1].document;
    //or is it... var f = window.frames[1].document;
    f.replaceChild(f.createElement("html"), f.documentElement);

    This hasn't solved my problem...

  6. #6
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    try replacing the iframe with a new one.
    Trinithis

  7. #7
    Join Date
    Oct 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm usinf Frame, not iframe.

    Please visit and give reply to this post.

    http://www.dynamicdrive.com/forums/s...ad.php?t=25328

Bookmarks

Posting Permissions

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