...

View Full Version : How do you write text to an inline frame?



Basscyst
09-27-2003, 10:14 PM
I've tried this among others -

document.getElementById('pane').document.write("hello");



<iframe src="blank.html" id="pane" height="300" width="600"></iframe>

Nothing seems to be working is it possible?

Thanks -
Basscyst

Basscyst
09-27-2003, 10:26 PM
Ahh I fingered it out you have to open it to write to it. Thanks anyway.

window.pane.document.open();
window.pane.document.write("Hello");
window.pane.document.close();

cheesebag
09-27-2003, 10:43 PM
Not really. document.write() automatically calls document.open() (and document.clear()) on a closed document. Your first attempt wasn't working because .getElementById() returns the element object, which doesn't have a document property. The second attempt uses a frame reference (same as window.frames.frame_name), returning the window object representing the iframe, which has the iframe's document object (like all window objects) as a property. Might try:


function IFRAME_write(iframe_id, HTML)
{
var IFrameDoc, oIframe = document.getElementById(iframe_id);
if (typeof oIframe != 'undefined')
{
if (oIframe.contentDocument)
IFrameDoc = oIframe.contentDocument;
else if (oIframe.contentWindow)
IFrameDoc = oIframe.contentWindow.document;
else if (oIframe.document)
IFrameDoc = oIframe.document;
if (IFrameDoc)
{
IFrameDoc.write(HTML);
IFrameDoc.close();
}
}
}

Basscyst
09-28-2003, 06:29 PM
Understood. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum