insertAdjacentHTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Thies

    insertAdjacentHTML

    To my surprise, insertAdjacentH TML is not supported in Netscape.

    Can this be prototyped, or are there similar DOM 2 methods?

    Jeff


  • Lasse Reichstein Nielsen

    #2
    Re: insertAdjacentH TML

    "Jeff Thies" <nospam@nospam. net> writes:
    [color=blue]
    > To my surprise, insertAdjacentH TML is not supported in Netscape.[/color]

    Yes, it's a proprietary IE method, as are innerText and innerHTML,
    although the latter turned out to be so popular that it is implemented
    in most new browsers anyway.
    [color=blue]
    > Can this be prototyped, or are there similar DOM 2 methods?[/color]

    It probably could, but only in Mozilla based browsers. Other browsers,
    like Opera and Safari wouldn't be helped by that, whereas using DOM 2
    methods would most likely work in all modern browsers and in IE.

    There are no DOM 2 methods that parse HTML. To use DOM 2 methods to
    create content, you either build it using document.create Element and
    document.create TextNode, or you include it in the page, invisible, and
    copies it around.

    If it's just a simple text, it's easy.

    var node = document.create TextNode("simpl e text");

    To insert it adjacent to an element, elem, you can do the following:

    before:
    elem.parentNode .insertBefore(n ode, elem);
    at beginning:
    elem.insertBefo re(node, elem.firstChild );
    at end:
    elem.appendChil d(node) or elem.insertBefo re(node, null);
    after:
    elem.parentNode .insertBefore(n ode, elem.nextSiblin g);

    The same works for more complicated nodes than just a plain text, e.g.,

    var node = document.create DocumentFragmen t();
    node.appendChil d(document.crea teTextNode("it "));
    var em = document.create Element("em");
    em.appendChild( document.create TextNode("is")) ;
    node.appendChil d(em);
    node.appendChil d(document.crea teTextNode(" easy!"));

    then insert node adjacent to an element as above.
    It's a litte verbose, but it's quite easy to get the hang of.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Martin Honnen

      #3
      Re: insertAdjacentH TML



      Jeff Thies wrote:
      [color=blue]
      > To my surprise, insertAdjacentH TML is not supported in Netscape.[/color]

      It somehow surprises me that that surprises you now after all the years
      Netscape 6/7 have been with us.
      [color=blue]
      > Can this be prototyped, or are there similar DOM 2 methods?[/color]

      Yes, it can be prototyped using createContextua lFragment, see


      however as createContextua lFragment is a Mozilla extension you might be
      better off to use DOM Level 2 only as already suggested.
      However Opera 7 also supports insertAdjacentH TML. Any Safari or
      Konqueror users reading here that could let us know whether those
      browsers support insertAdjacentH TML?
      --

      Martin Honnen


      Comment

      • Jeff Thies

        #4
        Re: insertAdjacentH TML


        "Martin Honnen" <mahotrash@yaho o.de> wrote in message
        news:40dd811d$1 @olaf.komtel.ne t...[color=blue]
        >
        >
        > Jeff Thies wrote:
        >[color=green]
        > > To my surprise, insertAdjacentH TML is not supported in Netscape.[/color]
        >
        > It somehow surprises me that that surprises you now after all the years
        > Netscape 6/7 have been with us.[/color]

        Well, I deserve that! My javascript mind has been on hiatus.

        NS6 always ran like a dog for me, fortunately it never captured much market
        share as most NS users stuck with NS4.

        NS7, Opera 7 and Safari has got me thinking again... about how much I
        forgot.

        Cheers,
        Jeff


        Comment

        • Jeff Thies

          #5
          Re: insertAdjacentH TML

          <snip>
          [color=blue]
          > Yes, it's a proprietary IE method, as are innerText and innerHTML,
          > although the latter turned out to be so popular that it is implemented
          > in most new browsers anyway.[/color]

          Do you know of any recent browsers that fail to implement innerHTML?

          Thanks,
          Jeff



          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: insertAdjacentH TML

            "Jeff Thies" <nospam@nospam. net> writes:
            [color=blue]
            > Do you know of any recent browsers that fail to implement innerHTML?[/color]

            No, but I don't know all recent browsers.

            I believe Safari supports it, but can't check it.
            I'm not so sure about ICEBrowser.

            What recent browsers are there?

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Jeff Thies

              #7
              Re: insertAdjacentH TML


              "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
              news:d63mme5u.f sf@hotpop.com.. .[color=blue]
              > "Jeff Thies" <nospam@nospam. net> writes:
              >[color=green]
              > > Do you know of any recent browsers that fail to implement innerHTML?[/color]
              >
              > No, but I don't know all recent browsers.
              >
              > I believe Safari supports it, but can't check it.[/color]

              Yes, it does.

              [color=blue]
              > I'm not so sure about ICEBrowser.
              >
              > What recent browsers are there?[/color]

              I asked over in alt.html and got this:

              <URL: http://www.download.com/sort/3150-2356-0-1-2.html? >

              There's only about 20 in the last month. I have no idea how many are IE
              based.

              Cheers,
              Jeff[color=blue]
              >
              > /L
              > --
              > Lasse Reichstein Nielsen - lrn@hotpop.com
              > DHTML Death Colors:[/color]
              <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue]
              > 'Faith without judgement merely degrades the spirit divine.'[/color]


              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: insertAdjacentH TML

                "Jeff Thies" <nospam@nospam. net> writes:
                [color=blue]
                > "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message[/color]
                [color=blue][color=green]
                >> What recent browsers are there?[/color][/color]
                ....[color=blue]
                > <URL: http://www.download.com/sort/3150-2356-0-1-2.html? >
                >
                > There's only about 20 in the last month. I have no idea how many are IE
                > based.[/color]

                IE based : Deepnet Explorer, Avant Browser, Slim Browser,
                Smart Bro, 27 Tools-in-1 Wichio Browser, GameNet
                Browser[1], Sports Browser, NetCaptor, KidSplorer,
                MyIE2, MyIE2 lite, Ace Explorer, Arlington Kiosk
                Browser, Advanced Browser, iRider, WindowSurfer,

                Mozilla based: Mozilla, Mozilla FireFox, SmartFox

                Other : Opera(2), Image Browser,

                Unknown : UltraBrowser(?) , Optimal Desktop(?), 550Access Browser(?).

                That is, of 23 browsers, *one* is not based on either IE, Mozilla or
                Opera technology: Image Browser, and it doesn't support scripting at
                all.

                Three fail to say anything about their technology (but I'll be very
                surpriced if they aren't using the IE browsers component)

                /L
                [1] Would you trust a browser manufacturer that sends their home page as
                "text/plain"? <URL:http://www.smartalec20 00.com/>
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • Randy Webb

                  #9
                  Re: insertAdjacentH TML

                  Lasse Reichstein Nielsen wrote:
                  [color=blue]
                  > [1] Would you trust a browser manufacturer that sends their home page as
                  > "text/plain"? <URL:http://www.smartalec20 00.com/>[/color]

                  Whats worse is a browser based on technology that displays that
                  text/plain as a webpage :-x

                  --
                  Randy
                  Chance Favors The Prepared Mind
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  Working...