RE: iframe ... does it have an innerHTML ?

Gregory Hill
Wed, 28 Jun 2006 15:05:32 -0000

Ah, sorry for being snippy.  I read it as ''no, that won''t
work, do this
instead'', which apparently isn''t what you were saying.  My
bad.  I owe
you a Mt. Dew or something :-)



But, I think it''s important to know that you can''t modify the
innerHTML
on a freshly created IFRAME element.  Until you write to it, there is no
document.body.



Greg



________________________________

From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of
Martinez, Andrew
Sent: Wednesday, June 28, 2006 8:39 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] iframe ... does it have an innerHTML ?



My use of innerHTML was only offered just in case he was going to be
adding multiple strings to the IFRAME not knowing that using
document.write clears the previously outputted text. I was hoping to
head off future problems with the same issue for a developer new to
JavaScript.



Your solution is truly a correct solution too. I was just trying to help
the new guy.



-Andrew Martinez



-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On
Behalf Of
Gregory Hill
Sent: Wednesday, June 28, 2006 10:24 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] iframe ... does it have an innerHTML ?



Well, you can''t do what you just wrote because until you put something
in the iframe, there is no iFrame.contentWindow.document.body.  He asked
about creating a hidden iframe and writing to it, the solution I posted
is the only cross-browser solution that I''ve seen.  And you''d
only lose
what was previously in the Iframe window, ie nothing, by overwriting it;
the parent document will not be affected.



The .src = ''/'' was a remnant from the code I was using to
avoid
''non-secure items on a secure page'' in IE, it can safely be
removed.



Greg



________________________________

From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of
Martinez, Andrew
Sent: Wednesday, June 28, 2006 6:42 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] iframe ... does it have an innerHTML ?



Important to remember that using document.open/close/write from
javascript during non-loading period will cause the current document
context to reset, meaning you lose what was previously there.



-   var iFrame = document.createElement(''IFRAME'');

-   iFrame.src = "/"; //pretty sure you don''t need this

-   iFrame.contentWindow.document.body.innerHTML = "blarrrrrrr";

-   iFrame.contentWindow.document.body.innerHTML += "more
BLARRRRRRRRR";





-Andrew Martinez



-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On
Behalf Of
Gregory Hill
Sent: Tuesday, June 27, 2006 4:51 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] iframe ... does it have an innerHTML ?



This should work:



        var iFrame   = document.createElement(''IFRAME'');

        iFrame.src = ''/'';

        iFrame.contentWindow.document.open();

        iFrame.contentWindow.document.write(sDocument);

        iFrame.contentWindow.document.close();



Greg



________________________________

From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Sam
Sent: Tuesday, June 27, 2006 2:43 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] iframe ... does it have an innerHTML ?



If I dynamically create a hidden iframe, how could I add a document in a
string to that element?



e.g.,



var sDocument = '' Hello
world. '';



I''ve tried several variations of appendChild, innerHTML,
document.innerHTML, createTextNode.



Argh!