Javascript in netscape navigator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sangwoo Im

    Javascript in netscape navigator

    Please take a look at my code. I made a script to scroll the contents of DIV
    tag. It works in IE, but not NN. I tried to use document.getEle mentById(id)
    function. It didn't work at all. I just want it to run in NN7.1 which is
    latest. Thank you in advance.

    <HTML>
    <HEAD>
    <TITLE>TEST</TITLE>
    <SCRIPT LANGUAGE="Javas cript">
    <!--
    var div1interval;
    function div1init()
    {
    for(j=0; j<2;j++)
    {
    div1.innerHTML += 1+"<BR>";
    }
    while((div1.scr ollHeight/2) <= parseInt(div1.s tyle.height))
    {
    div1.innerHTML += div1.innerHTML;
    }
    }
    function div1start()
    {
    div1interval=se tInterval("div1 scent();div1.sc rollTop+=5;",10 0);
    }
    function div1scent()
    {
    if(div1.scrollT op == (div1.scrollHei ght-parseInt(div1.s tyle.height)))
    {
    div1.scrollTop = (div1.scrollHei ght/2)-parseInt(div1.s tyle.height);
    }
    }
    -->
    </SCRIPT>
    </HEAD>
    <BODY>
    <div ID="div1" STYLE="overflow-y:hidden; width:100px; Height:101px;
    display:block;"
    onclick="alert( 'height: '+this.scrollHe ight+', Top: '+this.scrollTo p)">
    <SCRIPT LANGUAGE="Javas cript">
    <!--
    div1init();
    div1start();
    -->
    </SCRIPT>
    </div>
    </BODY>
    </HTML>
  • Lasse Reichstein Nielsen

    #2
    Re: Javascript in netscape navigator

    woo0609@aol.com (Sangwoo Im) writes:
    [color=blue]
    > Please take a look at my code. I made a script to scroll the contents of DIV
    > tag. It works in IE, but not NN. I tried to use document.getEle mentById(id)
    > function. It didn't work at all.[/color]

    That would depend on how you used it, obviosuly.
    [color=blue]
    > I just want it to run in NN7.1 which is latest.[/color]

    Aim higher :) There are other browsers than IE and Mozilla/Netscape.


    First, Does your HTML validate? (Answer: No. Make it before you go any
    further).

    HTML requires a DOCTYPE delaration.
    [color=blue]
    > <HTML>
    > <HEAD>
    > <TITLE>TEST</TITLE>
    > <SCRIPT LANGUAGE="Javas cript">[/color]

    In HTML 4, the type attribute is required. The language attribute is
    not necessary when you have type.
    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    No need for HTML-like comments.
    [color=blue]
    > var div1interval;
    > function div1init()
    > {
    > for(j=0; j<2;j++)
    > {
    > div1.innerHTML += 1+"<BR>";[/color]

    innerHTML is proprietary. I assume this function is only for testing
    though (filling the div with some arbitrary context).

    I don't think "scrollHeig ht" works the same in Mozilla/Netscape as in IE.
    It doesn't give the height of the entire content, just the height of the
    visible area. You need a different way to calculate the height of the hidden
    content.

    You are using "div1" as a global variable, but you haven't initialized
    it. In IE that would make it point to the element with id="div1". In
    other browsers it won't.

    This question comes up a lot. Is it time for an entry in the FAQ?

    <FAQENTRY>Why doesn't the global variable "divId" refer to the element
    with id="divId"?

    It does in Internet Explorer, but not in *many* other browsers. The
    recommended way of referring to an element with id="foo" is
    document.getEle mentById("foo")
    In order to support older browsers that doesn't implement this W3C DOM
    method, fallback to proprietary features can be used. In Internet Explorer
    4 (and WebTV?), you can use document.all["foo"] . In Netscape 4, maybe
    you can use document.layers["foo"] , but only if the element is absolutely
    positioned (or created with the Netscape 4 proprietary <layer> tag).

    <URL:http://www.mozilla.org/docs/web-developer/upgrade_2.html# dom_access>
    </FAQENTRY>
    (better ideas obviously welcome)
    [color=blue]
    > function div1start()
    > {
    > div1interval=se tInterval("div1 scent();div1.sc rollTop+=5;",10 0);[/color]

    Same problem here. Change "div1" into "document.getEl ementById('div1 ')"
    [color=blue]
    > }
    > function div1scent()
    > {[/color]

    Add
    var div1 = document.getEle mentById("div1" );
    so you won't have to change "div1" everywhere.
    [color=blue]
    > if(div1.scrollT op == (div1.scrollHei ght-parseInt(div1.s tyle.height)))[/color]

    You compare with ==. You would probably want to use ">=", since you scroll
    in steps of 5, so you can miss the exact value.

    You use "div1.style.hei ght" to get the current height. Just be aware that it
    only works when div1 has its height set in the style attribute (as it does).
    Another, non-standard, method is to use div1.offsetHeig ht.

    ....[color=blue]
    > <div ID="div1" STYLE="overflow-y:hidden; width:100px; Height:101px;[/color]

    "overflow-y" is a proprietary IE property, not CSS. Try "overflow:hidde n".
    [color=blue]
    > display:block;"[/color]

    display:block is default for a div.


    I still can't get it working in Opera.
    /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

    • Sangwoo Im

      #3
      Re: Javascript in netscape navigator

      Thank you for your replying post.

      I will keep reading thru what you wrote multiple times then try to fix it.

      However, I wonder whether a documentation which explains the difference of
      Javascript among various browsers exists or not.

      Anybody has an idea?

      Comment

      • Richard Cornford

        #4
        Re: Javascript in netscape navigator

        "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
        news:he0col2r.f sf@hotpop.com.. .
        <snip>[color=blue]
        >This question comes up a lot. Is it time for an entry in the FAQ?[/color]

        This is another of those cases where the question itself is not really
        asked often but the information is very frequently included as part of
        answers. That would suggest that maybe it should be in the FAQ (as other
        entries (eval (#FAQ4_40), for example) got in by the same criteria).
        [color=blue]
        ><FAQENTRY>Wh y doesn't the global variable "divId" refer to
        >the element with id="divId"?[/color]

        I wonder whether that question shouldn't be worded "Why doesn't the
        global variable "divId" always refer to the element with id="divId"?" -
        or - "Why doesn't the global variable "divId" refer to the element with
        id="divId" in all browsers?" (though the latter would mean re-wording
        the opening sentence).
        [color=blue]
        > It does in Internet Explorer, but not in *many* other[/color]

        We could quibble about "*many*" as reproducing this IE feature seems to
        be quite common among modern browsers, Mozilla/Gecko browsers being
        primarily the ones that render this IE shortcut invalid in cross-browser
        scripting.
        [color=blue]
        > browsers. The recommended way of referring to an element
        > with id="foo" is
        > document.getEle mentById("foo")
        > In order to support older browsers that doesn't implement
        > this W3C DOM method, fallback to proprietary features can be
        > used. In Internet Explorer 4 (and WebTV?), you can use
        > document.all["foo"] . In Netscape 4, maybe you can use
        > document.layers["foo"] , but only if the element is absolutely
        > positioned (or created with the Netscape 4 proprietary
        > <layer> tag).
        >
        ><URL:http://www.mozilla.org/docs/web-deve...html#dom_acces[/color]
        s>[color=blue]
        > </FAQENTRY>
        > (better ideas obviously welcome)[/color]

        In Netscape 4 elements with - position:relati ve - also appear in the -
        layers - collection so maybe the last sentence should go "..., but only
        if the element is CSS positioned (or created with ...".

        Thinking about the role of FAQ entries, it seems to me that the purpose
        of posting a URL reference to a part of the FAQ is to avoid repeating
        the same explanation in response to questions. To that end I would
        probably be a bit more long-winded and want to include an example
        fallback function:-

        <longer_proposa l>
        A common shortcut in accessing DOM elements that have ID attributes
        (introduced by IE and reproduced in some other browsers) is to use the
        ID string as an identifier for the element. However, not all browsers
        support this shortcut and more general methods exist for accessing IDed
        elements. The widest support is offered by the document.getEle mentById
        method, which is part of the W3C DOM standard and implemented in most
        modern browsers (including IE from version 5.0). So an element with
        id="foo" can be referenced with:-

        var el = document.getEle mentById("foo") ;

        In order to support older browsers that doesn't implement this W3C DOM
        method, fallback to proprietary features can be used. In Internet
        Explorer 4 (and WebTV?), you can use document.all["foo"] . In Netscape
        4, maybe you can use document.layers["foo"] , but only if the element is
        CSS positioned (or created with the Netscape 4 proprietary <layer> tag).
        E.G.:-

        function getElementWithI d(id){
        if(document.get ElementById){ //prefer the W3C DOM method.
        return document.getEle mentById(id);
        }else if(document.all ){ //fallback for IE 4(and some others)
        return document.all[id];
        }else if(document.lay ers){ //fallback for Net 4 (sometimes)
        return document.layers[id]; //Will not work for layers nested
        //within layers. A recursive
        //search of nested layers would
        //be needed to find such a layer
        }
        } // remember to test the value returned from this function as some
        // browsers do not support any of the methods used here.
        </longer_proposal >

        - but FAQ entries also need to be short so maybe not.

        Richard.


        Comment

        • Jim Ley

          #5
          Re: Javascript in netscape navigator

          On Mon, 8 Dec 2003 15:04:32 -0000, "Richard Cornford"
          <Richard@litote s.demon.co.uk> wrote:
          [color=blue]
          >"Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message[/color]
          [color=blue][color=green]
          >><FAQENTRY>W hy doesn't the global variable "divId" refer to
          >>the element with id="divId"?[/color][/color]

          I'm reading very infrequently at the minute, whilst I do pick up the
          FAQENTRY's when later reviewing, the main motivation for a session at
          editing the FAQ is lots of FAQENTRY's being seen, if you could CC me
          these it may get them done quicker...
          [color=blue]
          >- but FAQ entries also need to be short so maybe not.[/color]

          I like the idea, and think it would be a valuable addition, but
          shorter for sure!

          Jim.
          --
          comp.lang.javas cript FAQ - http://jibbering.com/faq/

          Comment

          Working...