Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inner/outerHTML setting for mozilla

2 views
Skip to first unread message

Martin Honnen

unread,
Jan 4, 2000, 3:00:00 AM1/4/00
to
With the new getter/setter feature of JS1.5 it is possible to emulate IE
properties innerHTML and outerHTML in Mozilla. Here are setter functions
which allow assigning an html source string to the innerHTML or
outerHTML property of any HTMLElement:

<SCRIPT LANGUAGE="JavaScript1.5">
HTMLElement.prototype.innerHTML setter =
function (html) {
while (this.hasChildNodes())
this.removeChild(this.lastChild);
this.innerHTMLInput = html;
var range = document.createRange();
range.setStartAfter(this);
var docFrag = range.createContextualFragment(html);
this.appendChild(docFrag);
};
HTMLElement.prototype.outerHTML setter =
function (html) {
this.outerHTMLInput = html;
var range = document.createRange();
range.setStartBefore(this);
var docFrag = range.createContextualFragment(html);
this.parentNode.replaceChild(docFrag, this);
}
</SCRIPT>


Does someone know whether mozilla exposes some api to construct a html
source string of a document fragment?? Then the getter functions would
be easy otherwise someone would need to write some dom traversal stuff.


--

Martin Honnen

http://home.t-online.de/home/martin.honnen/jsgoddies.html


Thor Larholm

unread,
May 17, 2000, 3:00:00 AM5/17/00
to
"charles" <cha...@moonfield.com> wrote in message
news:39239D97...@moonfield.com...
> Hi,
>
> Does aybody know the equivalent of insertAdjacentHTML that workt in
netscape
> 6?
> I would like to let users of my site to dynamically insert combinations
of
> text en html into a document, so that it will work in netscape 6.
> Is there an existing script for that?
>
> Danny Goodman wrote this about is:
> "When the dynamic content involves combinations of HTML elements and text
> nodes, the DOM methodology gets more complex, since you have to create the
> elements or text nodes and assemble the objects in the desired sequence".

NS6/Mozilla has the range.createContextualFragment() function, which can be
used to create a set of DOM elements from an HTML string.

Using this, I have duplicated insertAdjacentHTML(), insertAdjacentText() and
insertAdjacentElement() to NS6/Mozilla, and added the same insertion
behaviour as IE4/5 exposes.

http://chat.betachat.dk/dom/interactive.html


--
Thor Larholm

charles

unread,
May 18, 2000, 3:00:00 AM5/18/00
to Martin Honnen
Hi,

Does aybody know the equivalent of insertAdjacentHTML that workt in netscape
6?
I would like to let users of my site to dynamically insert combinations of
text en html into a document, so that it will work in netscape 6.
Is there an existing script for that?

Danny Goodman wrote this about is:
“When the dynamic content involves combinations of HTML elements and text
nodes, the DOM methodology gets more complex, since you have to create the
elements or text nodes and assemble the objects in the desired sequence”.

Unfortunatly he did not tell how or where to find a script like that.

Thanks.

cha...@monfield.nl

charles.

charles

unread,
May 18, 2000, 3:00:00 AM5/18/00
to
0 new messages