Problems with Netscape

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

    Problems with Netscape

    Hi,

    when I try to see the effect of the following script
    I do not see anything when using Netscape Navigator whereas
    InternetExplore r ist ok.

    In Netscape Javascript is activated. What could be the problem?

    Thank you for your help.


    <head>
    <STYLE>.spansty le {
    COLOR: green; FONT-FAMILY: Verdana; FONT-SIZE: 10pt;
    FONT-WEIGHT: bold; POSITION: absolute; TOP: -50px; VISIBILITY: visible
    }
    </STYLE>
    <SCRIPT>
    var x,y
    var step=20
    var flag=0
    //
    var message="THIS IS A TEST!!"
    message=message .split("")
    var xpos=new Array()
    for (i=0;i<=message .length-1;i++) {
    xpos[i]=-50
    }
    var ypos=new Array()
    for (i=0;i<=message .length-1;i++) {
    ypos[i]=-50
    }
    function handlerMM(e){
    x = (document.layer s) ? e.pageX :
    document.body.s crollLeft+event .clientX
    y = (document.layer s) ? e.pageY :
    document.body.s crollTop+event. clientY
    flag=1
    }
    function makesnake() {
    if (flag==1 && document.all) {
    for (i=message.leng th-1; i>=1; i--) {
    xpos[i]=xpos[i-1]+step
    ypos[i]=ypos[i-1]
    }
    xpos[0]=x+step
    ypos[0]=y
    for (i=0; i<message.lengt h-1; i++) {
    var thisspan = eval("span"+(i) +".style")
    thisspan.posLef t=xpos[i]
    thisspan.posTop =ypos[i]
    }
    }
    else if (flag==1 && document.layers ) {
    for (i=message.leng th-1; i>=1; i--) {
    xpos[i]=xpos[i-1]+step
    ypos[i]=ypos[i-1]
    }
    xpos[0]=x+step
    ypos[0]=y
    for (i=0; i<message.lengt h-1; i++) {
    var thisspan = eval("document. span"+i)
    thisspan.left=x pos[i]
    thisspan.top=yp os[i]
    }
    }
    var timer=setTimeou t("makesnake()" ,30)
    }
    </SCRIPT>
    </head>
    <body onload="makesna ke()" style="OVERFLOW-X: hidden; OVERFLOW-Y:
    scroll; WIDTH: 100%" BACKGROUND>
    <SCRIPT>
    <!-- Beginning of JavaScript -
    for (i=0;i<=message .length-1;i++) {
    document.write( "<span id='span"+i+"' class='spanstyl e'>")
    document.write( message[i])
    document.write( "</span>")
    }
    if (document.layer s){
    document.captur eEvents(Event.M OUSEMOVE);
    }
    document.onmous emove = handlerMM;
    // - End of JavaScript - -->
    </SCRIPT>
    </body>
    </html>
  • Lasse Reichstein Nielsen

    #2
    Re: Problems with Netscape

    ALuPin@web.de (ALuPin) writes:
    [color=blue]
    > when I try to see the effect of the following script
    > I do not see anything when using Netscape Navigator whereas
    > InternetExplore r ist ok.[/color]
    [color=blue]
    > In Netscape Javascript is activated. What could be the problem?[/color]

    Probably you using proprietary IE features. Let's have a look

    [color=blue]
    > function handlerMM(e){[/color]

    Looks like an event handler. That would mean that the 'e' is the event
    in non-IE browsers (whereas IE keeps the event as the global variable
    "event").
    [color=blue]
    > x = (document.layer s) ? e.pageX :
    > document.body.s crollLeft+event .clientX[/color]

    And right on, if document.layers exists, then "e" is used, otherwise
    "event" is used. However, Netscape 6+ doesn't have a document.layers
    object, but it should use the "e" varible, so this code fails completely.

    It looks like it was written for IE and Netscape 4 exclusively, and
    therefore it fails in all other browsers.
    [color=blue]
    > function makesnake() {
    > if (flag==1 && document.all) {[/color]

    this test for "document.a ll" is probably meant to detect IE. That is
    no longer the case. Other browsers, e.g., Opera, also has document.all
    collections.
    [color=blue]
    > var thisspan = eval("span"+(i) +".style")[/color]

    This is blatant misuse of eval, as well as IE specific coding.

    If "i" is, e.g., 2, then this will evaluate the expression
    "span2.styl e". I assume "span2" is the id/name of a span element. IE
    makes global variables available that refer to named elements. Other
    browsers does not.

    It could just be written as:
    window["span"+i]
    in IE, and it would even be faster.
    [color=blue]
    > var thisspan = eval("document. span"+i)[/color]

    This accesses "document.span2 ". It could just be written as:
    document["span"+i];

    Neither of these two access methods ("window['span'+i]" or
    "document['span'+i]") will work in Netscape 6+. Instead you should use
    "document.getEl ementById('span '+i)"
    [color=blue]
    > <body onload="makesna ke()" style="OVERFLOW-X: hidden; OVERFLOW-Y:
    > scroll; WIDTH: 100%" BACKGROUND>[/color]

    OVERFLOW-X and OVERFLOW-Y are prorietary IE features. The background
    attribute should have a value.
    [color=blue]
    > <SCRIPT>[/color]

    The "type" attribute is required on script tags in HTML 4. Use
    <script type="text/javascript">
    [color=blue]
    > <!-- Beginning of JavaScript -[/color]

    This line is not needed.

    /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

    • Richard Cornford

      #3
      Re: Problems with Netscape

      ALuPin wrote:[color=blue]
      > when I try to see the effect of the following script
      > I do not see anything when using Netscape Navigator whereas
      > InternetExplore r ist ok.
      >
      > In Netscape Javascript is activated. What could be the problem?[/color]
      <snip>[color=blue]
      > function makesnake() {
      > if (flag==1 && document.all) {[/color]
      <snip>[color=blue]
      > var thisspan = eval("span"+(i) +".style")[/color]

      Any script author who uses - eval - to resolve a dot notation property
      accessor doesn't really understand javascript. Unsurprisingly people who
      don't understand javascript don't tend to create very good scripts, so
      expecting the results to be cross-browser or reliable is probably
      unrealistic.

      <snip>[color=blue]
      > else if (flag==1 && document.layers ) {[/color]
      <snip>

      This script has an - if(document.all ){ - branch, which will be taken by
      IE, Opera, Konqueror, Safari, IceBrowser and others. It also has an -
      else if(document.lay ers) - branch, which would be followed by Netscape 4
      and a couple of close imitators. But Netscape 6+ dropped the -
      document.layers - collection in favour of implementing W3C DOM standards
      and so there is no branch in this code that will be taken by Netscape
      6+, Mozilla or any other Gecko-based browser.

      The balance of probability is that this is a script from some published
      copy-and-paste collection and was written at the time when IE 4 and
      Netscape 4 were the dominant scriptable browsers, but is now out of date
      (in its browser scripting and implementation style). That is the problem
      with copy-and-paste scripts (apart from the lack of any qualified
      quality control overseeing their publication); once they have been
      placed on the Internet there they stay, a trap for the unwary and
      contributing to making the internet worse when they find themselves
      being used by people who don't know any better and only superficially
      test in one browsers.

      Richard.


      Comment

      Working...