If I dynamically create a hidden iframe, how could I add a document in a string to that element? e.g., var sDocument = ''<html><head></head><body>Hello world.</body></html>''; I''ve tried several variations of appendChild, innerHTML, document.innerHTML, createTextNode. Argh! _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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 = ''<html><head></head><body>Hello
world.</body></html>'';
I''ve tried several variations of appendChild, innerHTML,
document.innerHTML, createTextNode.
Argh!
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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 = ''<html><head></head><body>Hello
world.</body></html>'';
I''ve tried several variations of appendChild, innerHTML,
document.innerHTML, createTextNode.
Argh!
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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";
resetting the context of the enclosing body? This means reloading an iframe
will ... fire a body onload event or what?
are you sure it doesn''t reset the context of the iframe alone? (hopeful
look)
<take a moment to ready what was actually written>
.. so using innerHTML avoids the context reset altogether...
thanks
</>
Sam
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
It sounds like you answered your own question in your response email...but I
will respond just because there is another question you ask that you
didn''t already answer yourself.
Using document.write post-load does not fire an onload. It just resets the
document''s text/html.
A simple test:
An IFRAME is just a nested window context, with some quirks. So, opening a new
window is just like an IFRAME.
Lets go to www.google.com <http://www.google.com/>
In the URL/address bar, clear any text there.
Type: javascript:document.write(''omg where did google go''
);
Press enter.
No onload, but google is now gone!
-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 Sam
Sent: Wednesday, June 28, 2006 10:05 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";
resetting the context of the enclosing body? This means reloading an iframe
will ... fire a body onload event or what?
are you sure it doesn''t reset the context of the iframe alone? (hopeful
look)
<take a moment to ready what was actually written>
.. so using innerHTML avoids the context reset altogether...
thanks
</>
Sam
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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 = ''<html><head></head><body>Hello
world.</body></html>'';
I''ve tried several variations of appendChild, innerHTML,
document.innerHTML, createTextNode.
Argh!
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Lets go to www.google.com <http://www.google.com/>
In the URL/address bar, clear any text there.
Type: javascript:document.write(''omg where did google go''
);
Press enter.
No onload, but google is now gone!
----------------------------------------------------------
Thanks. One last question to clean up...
oMyDiv = document.createElement(''div'');
document.body.appendChild(oMyDiv);
sMyText = ''Howdy! This is western text!'';
oMyDiv.innerHTML = sMyText;
oMyText = document.createTextNode(sMyText);
oMyDiv.appendChild(oMyText);
Does one method of adding innerHTML have benefits / features that the other
does not?
Sam
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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 = ''<html><head></head><body>Hello
world.</body></html>'';
I''ve tried several variations of appendChild, innerHTML,
document.innerHTML, createTextNode.
Argh!
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Most people agree, that creating textNodes is the correct way to handle adding
text to a DOM node. Other than that here are the arguments:
- Using a text node: It lets you add text w/o clobbering other child
nodes.
- Using innerHTML: you destroy all previous child nodes and text.
- Using innerHTML: you could use innerHTML += "my text" to
append text as well and that will just create a new text node for you.
- Using a text node : you can insert your new node before, after, or
between other DOM nodes
- Using innerHTML is faster than creating new nodes
- Using innerHTML: will let you put invalid HTML on your page via
scripts (the biggest argument against)
And here is the kicker:
- In IE only: if you use innerHTML there is a 1ms-100ms lag between the
DOM tree/DOM nodes being updated with your new HTML. However it is instantly
visible to the user.
Meaning, if you set the innerHTML of an element to HTML that will create other
DOM nodes, you will not be able to do element.childNodes[] right away. There
will be a time lag before the DOM is updated. This only matters in time
sensitive code where lots of objects and data is moving and changing. I found it
by chance and it has only ever affect one of my scripts in years of work. Again,
this only happens in IE.
It was 2 days of intense pain tracking down a bug in some really complex JS code
that was time sensitive that lead me to the above...
Other than that is it preference. I personally only use innerHTML when the text
node is the only thing being put in an element. If I am putting multiple
separate elements or trying to preserve previous child elements, I use nodes.
-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 Sam
Sent: Wednesday, June 28, 2006 10:34 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] iframe ... does it have an innerHTML ?
Lets go to www.google.com <http://www.google.com/>
In the URL/address bar, clear any text there.
Type: javascript:document.write(''omg where did google go''
);
Press enter.
No onload, but google is now gone!
----------------------------------------------------------
Thanks. One last question to clean up...
oMyDiv = document.createElement(''div'');
document.body.appendChild(oMyDiv);
sMyText = ''Howdy! This is western text!'';
oMyDiv.innerHTML = sMyText;
oMyText = document.createTextNode(sMyText);
oMyDiv.appendChild(oMyText);
Does one method of adding innerHTML have benefits / features that the other does
not?
Sam
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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 = ''<html><head></head><body>Hello
world.</body></html>'';
I''ve tried several variations of appendChild, innerHTML,
document.innerHTML, createTextNode.
Argh!
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
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. The new guy appreciates your help... Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
And here is the kicker: - In IE only: if you use innerHTML there is a 1ms-100ms lag between the DOM tree/DOM nodes being updated with your new HTML. However it is instantly visible to the user. I have been using innerHTML to insert Ajax retrieved content and applying observers to that content using EventSelectors without any problem. But I''d like to be safe. Is there a safer way to know when the DOM tree is ready before applying observers ? Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org
2006-Jul-01 19:02 UTC
RE: iframe ... does it have an innerHTML ?
> And here is the kicker: > - In IE only: if you use innerHTML there is a 1ms-100ms lag > between > the DOM tree/DOM nodes being updated with your new HTML. However it is > instantly visible to the user. > > > I have been using innerHTML to insert Ajax retrieved content and applying > observers to that content using EventSelectors without any problem. > > But I''d like to be safe. Is there a safer way to know when the DOM tree > is > ready before applying observers ?You could use DOM.Ready, specifically the onIdReady() function. http://openjsan.org/doc/a/au/autarch/DOM/Ready/0.13/lib/DOM/Ready.html
Andrew Martinez (RIT Student)
2006-Jul-02 12:16 UTC
RE: iframe ... does it have an innerHTML ?
Depends on how you are doing it. If you are using the elements .innerHTML to get the data out again, you are fine. If you are using the DOM functionality (.childNodes,.createElement,etc) you will need to take in account for the update lag in IE. However, I have not heard of this onReady() functionality before. I will have to look into it as it sounds like an amazingly helpful idea for IE. ********************************* Andrew Martinez (apm9733-H6Ufl4FQnQQ@public.gmane.org) *********************************> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs- > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of mpeters-aUYv5hkjw45l57MIdRCFDg@public.gmane.org > Sent: Saturday, July 01, 2006 3:03 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: RE: [Rails-spinoffs] iframe ... does it have an innerHTML ? > > > > And here is the kicker: > > - In IE only: if you use innerHTML there is a 1ms-100ms lag > > between > > the DOM tree/DOM nodes being updated with your new HTML. However it is > > instantly visible to the user. > > > > > > I have been using innerHTML to insert Ajax retrieved content and > applying > > observers to that content using EventSelectors without any problem. > > > > But I''d like to be safe. Is there a safer way to know when the DOM tree > > is > > ready before applying observers ? > > You could use DOM.Ready, specifically the onIdReady() function. > > http://openjsan.org/doc/a/au/autarch/DOM/Ready/0.13/lib/DOM/Ready.html > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On Wednesday 28 June 2006 07:53, Martinez, Andrew wrote:> Most people agree, that creating textNodes is the correct way to handle > adding text to a DOM node. Other than that here are the arguments: > > Using innerHTML: you could use innerHTML += "my text" to append text as well > and that will just create a new text node for you.well, if you have any event handlers on the nodes contained by the node you''re doing .innerHTML on, it will destroy those as well, since it doesn''t just automagically create a new text node, it replaces the old innerHTML with the new innerHTML and then parses it looking for nodes. oh, and you leak memory if there were event handlers there as well :( innerHTML is evil! But, unfortunately, very convenient, and in almost every browser available, far far faster than using ''proper'' DOM manipulation. -Jeremy -- Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org http://www.pirate-party.us/ -- defend your rights _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs