PDA

View Full Version : Help regarding document.clear()



BNArun
10-03-2007, 04:50 AM
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.

Trinithis
10-03-2007, 04:57 AM
To clear the body tag, but not the head tag:

document.documentElement.replaceChild(document.createElement("body"), document.body);

To clear everything:

document.replaceChild(document.createElement("html"), document.documentElement);

One that works with XML as well:

document.replaceChild(document.createElement(document.documentElement.tagName), document.documentElement);

BNArun
10-03-2007, 05:28 AM
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?

Trinithis
10-03-2007, 06:00 AM
I forget how to use frames very well, but try this:


var f = window.parent.frames[1].document;
//or is it... var f = window.frames[1].document;
f.replaceChild(f.createElement("html"), f.documentElement);

BNArun
10-03-2007, 08:08 AM
I forget how to use frames very well, but try this:


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... :(

Trinithis
10-03-2007, 03:47 PM
try replacing the iframe with a new one.

BNArun
10-03-2007, 03:51 PM
I'm usinf Frame, not iframe.

Please visit and give reply to this post.

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