Browsers and onLoad

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

    Browsers and onLoad

    I am very new to javaScript, and I am hoping someone can explain the
    differance between the following two browsers and how to deal with thier
    differant approach to firing the onLoad event.

    The following web page is for my own use only, therefor I am uninterested in
    the Netscape platform.

    At home I have the following browser "Microsoft Internet Explorer4.0
    (compatible; MSIE 5.0; Windows 98; DigExt)" and my web page loads as
    planned. The onLoad event is fired when all the images are loaded, and until
    they are fully loaded progreess can be followed on the status bar.

    At work I have "Microsoft Internet Explorer4.0 (compatible; MSIE 6.0;
    Windows 98)"... Now this performs very differantly, The onLoad event is
    fired as soon as the HTML is loaded (which is a very long time before all
    the images are loaded) Also, because the browser considers loading to be
    complete, No progress on the images downloading is given on the status bar.


    The following link is to the first page, this gives the link to the second
    page that is causing the headache. If you do decide to view the page, choose
    4 days at 24 hours!



    As I am new to javaScript, I would welcome any advice / sugestions as to
    writing style and improvements that I could make

    regards
    Suart

    the following is the script :-

    <Script>
    var dwellTime=2
    var pos=''
    if (location.href. indexOf('?')!= -1){
    qwert =location.href. slice(location. href.indexOf('? ')+1)
    var dy=qwert.slice( 2)
    var int=qwert.slice (0,2-qwert.length)
    }
    parent.window.m oveTo(0,0)
    parent.window.r esizeTo(screen. availWidth,scre en.availHeight)
    if(screen.width ==800){
    var wth=632;var hgt=518
    }else{
    var wth=790;var hgt=648
    }
    var pics=(24/int)*dy
    var img=new Array()
    var hrs=''
    for(var i=0;i<pics;i++) {
    hrs=i*int
    if (hrs==0){hrs='0 0'}
    img[i] = new Image(wth,hgt)
    img[i].src= 'http://129.13.102.67/wz/pics/Rtavn'+hrs+'1.g if'
    }

    function opener(){
    document.images[0].src=img[0].src
    pos=0
    }

    function fire(q){
    if(q>0){pos++}e lse{pos--}
    if (pos==-1){pos=img.leng th-1}
    if (q==1&&pos==img .length){pos=0}
    document.images[0].src=img[pos].src
    }
    function auto(b){
    if (b){
    pos++
    if (pos==img.lengt h){pos=0}
    document.images[0].src=img[pos].src
    timerID=setTime out("auto(1)",d wellTime*1000)
    }else{
    clearTimeout(ti merID)
    return
    }
    }


    function dwell(t){
    if(t){
    dwellTime=dwell Time+0.5
    }else{
    dwellTime=dwell Time-0.5
    if (dwellTime<0){d wellTime=0}
    }
    }
    </Script>



  • Thomas 'PointedEars' Lahn

    #2
    Re: Browsers and onLoad

    Stuart wrote:
    [color=blue]
    > At home I have the following browser "Microsoft Internet Explorer4.0
    > (compatible; MSIE 5.0; Windows 98; DigExt)" and my web page loads as
    > planned. The onLoad event is fired when all the images are loaded, and
    > until they are fully loaded progreess can be followed on the status bar.
    >
    > At work I have "Microsoft Internet Explorer4.0 (compatible; MSIE 6.0;
    > Windows 98)"... Now this performs very differantly, The onLoad event is
    > fired as soon as the HTML is loaded (which is a very long time before all
    > the images are loaded) Also, because the browser considers loading to be
    > complete, No progress on the images downloading is given on the status
    > bar.[/color]

    This is a known issue, a test case can be found at


    All you can do is to use the onload event for each img/Image element/object
    and invoke a function that counts the number of images being already loaded.
    If the number reaches document.images .length or a number you specify, you
    invoke what should be executed onload of the document. Note that the
    `onload' event handler is not specified for `img' elements in HTML but you
    can assign it via the DOM in IE.
    [color=blue]
    > <Script>[/color]

    The type attribute is missing for valid HTML 4:

    <script type="text/javascript">
    [color=blue]
    > var dwellTime=2[/color]

    It is good style to end JavaScript statements with `;'.
    [color=blue]
    > var pos=''
    > if (location.href. indexOf('?')!= -1){
    > qwert =location.href. slice(location. href.indexOf('? ')+1)
    > var dy=qwert.slice( 2)
    > var int=qwert.slice (0,2-qwert.length)
    > }[/color]

    Use `location.searc h' instead.
    [color=blue]
    > parent.window.m oveTo(0,0)
    > parent.window.r esizeTo(screen. availWidth,scre en.availHeight)
    > if(screen.width ==800){[/color]

    Do not do this, the property values of the `screen' object are
    unreliable and the window is best sized as the user wishes it.

    Besides, so-called "optimizati on for screen resolution" is
    neither required for good design nor recommended.
    [color=blue]
    > function opener(){
    > document.images[0].src=img[0].src
    > pos=0
    > }[/color]

    This is unlikely to work. AFAIS in web browsers, functions are methods of
    the global or top-leve-object, with is the `window' object. But this object
    has a non-function property called `opener' that references the window that
    has opened the current window with scripting. That property will be
    overwritten here at best.


    PointedEars

    Comment

    • Stuart

      #3
      Re: Browsers and onLoad


      Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote in message
      news:bpdd3u$1m9 b47$9@ID-107532.news.uni-berlin.de...[color=blue]
      > Stuart wrote:
      >[color=green]
      > > At home I have the following browser "Microsoft Internet Explorer4.0
      > > (compatible; MSIE 5.0; Windows 98; DigExt)" and my web page loads as
      > > planned. The onLoad event is fired when all the images are loaded, and
      > > until they are fully loaded progreess can be followed on the status bar.
      > >
      > > At work I have "Microsoft Internet Explorer4.0 (compatible; MSIE 6.0;
      > > Windows 98)"... Now this performs very differantly, The onLoad event is
      > > fired as soon as the HTML is loaded (which is a very long time before[/color][/color]
      all[color=blue][color=green]
      > > the images are loaded) Also, because the browser considers loading to be
      > > complete, No progress on the images downloading is given on the status
      > > bar.[/color]
      >
      > This is a known issue, a test case can be found at
      > http://www.netz-notizen.de/angedacht...onload/b0.html[/color]

      its in a foreign language!
      [color=blue]
      >
      > All you can do is to use the onload event for each img/Image[/color]
      element/object[color=blue]
      > and invoke a function that counts the number of images being already[/color]
      loaded.[color=blue]
      > If the number reaches document.images .length or a number you specify, you
      > invoke what should be executed onload of the document. Note that the
      > `onload' event handler is not specified for `img' elements in HTML but you
      > can assign it via the DOM in IE.[/color]

      Looks interesting, will give it a go.......how does the image onload event
      deal with images that are not availabe?

      [color=blue]
      >[color=green]
      > > <Script>[/color]
      >
      > The type attribute is missing for valid HTML 4:[/color]

      ok
      [color=blue]
      >
      > <script type="text/javascript">
      >[color=green]
      > > var dwellTime=2[/color]
      >
      > It is good style to end JavaScript statements with `;'.[/color]

      ok
      [color=blue]
      >[color=green]
      > > var pos=''
      > > if (location.href. indexOf('?')!= -1){
      > > qwert =location.href. slice(location. href.indexOf('? ')+1)
      > > var dy=qwert.slice( 2)
      > > var int=qwert.slice (0,2-qwert.length)
      > > }[/color]
      >
      > Use `location.searc h' instead.[/color]

      I spent ages working out how to extract the bit after the "?"...I was quite
      pround of my effort until you point out the purpose defined function :-)

      [color=blue]
      >[color=green]
      > > parent.window.m oveTo(0,0)
      > > parent.window.r esizeTo(screen. availWidth,scre en.availHeight)
      > > if(screen.width ==800){[/color]
      >
      > Do not do this, the property values of the `screen' object are
      > unreliable and the window is best sized as the user wishes it.[/color]

      Yes, I totally agree, however, as this page is for my own use only I decided
      to add this auto sizeing....
      [color=blue]
      >
      > Besides, so-called "optimizati on for screen resolution" is
      > neither required for good design nor recommended.
      >[/color]
      [color=blue][color=green]
      > > function opener(){
      > > document.images[0].src=img[0].src
      > > pos=0
      > > }[/color]
      >
      > This is unlikely to work. AFAIS in web browsers, functions are methods of
      > the global or top-leve-object, with is the `window' object. But this[/color]
      object[color=blue]
      > has a non-function property called `opener' that references the window[/color]
      that[color=blue]
      > has opened the current window with scripting. That property will be
      > overwritten here at best.
      >[/color]

      This was a bit of an accident, I did not realise "opener" was a javaScipt
      function.....su prisingly it works fine!.....It was also a little unusual for
      me to use a normal word as an object name, I normally misspell words for
      object names and variables to avoid this sort of problems.
      [color=blue]
      >
      > PointedEars[/color]

      Many thanks for your views, I will use your advice!


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Browsers and onLoad

        Stuart wrote:
        [color=blue]
        > Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote [...][color=green]
        >> Stuart wrote:[color=darkred]
        >> > At home I have the following browser "Microsoft Internet Explorer4.0
        >> > (compatible; MSIE 5.0; Windows 98; DigExt)" and my web page loads as
        >> > planned. The onLoad event is fired when all the images are loaded, and
        >> > until they are fully loaded progreess can be followed on the status bar.
        >> >
        >> > At work I have "Microsoft Internet Explorer4.0 (compatible; MSIE 6.0;
        >> > Windows 98)"... Now this performs very differantly, The onLoad event is
        >> > fired as soon as the HTML is loaded (which is a very long time before[/color][/color]
        > all[/color]
        ^^[1]
        [color=blue][color=green][color=darkred]
        >> > the images are loaded) Also, because the browser considers loading to be
        >> > complete, No progress on the images downloading is given on the status
        >> > bar.[/color]
        >>
        >> This is a known issue, a test case can be found at
        >> http://www.netz-notizen.de/angedacht...onload/b0.html[/color]
        >
        > its in a foreign language![/color]

        Google is your friend. [psf 6.1]

        Click the button and see what happens, especially
        when you force reload from the server (Shift+Refresh) .
        [color=blue][color=green]
        >> All you can do is to use the onload event for each img/Image[/color]
        > element/object[/color]
        ^^[1]
        [color=blue][color=green]
        >> and invoke a function that counts the number of images being already[/color]
        > loaded.[/color]
        ^^[1]
        [color=blue][color=green]
        >> If the number reaches document.images .length or a number you specify, you
        >> invoke what should be executed onload of the document. Note that the
        >> `onload' event handler is not specified for `img' elements in HTML but you
        >> can assign it via the DOM in IE.[/color]
        >
        > Looks interesting, will give it a go.......how does the image onload event
        > deal with images that are not availabe?[/color]

        Test it. I think the event will not fire then, but
        you still have an Image object to reference to.
        [color=blue][color=green][color=darkred]
        >> > [location.href substring extraction][/color]
        >>
        >> Use `location.searc h' instead.[/color]
        >
        > I spent ages working out how to extract the bit after the "?"...I was quite
        > pround of my effort until you point out the purpose defined function :-)[/color]

        JFTR: location.search is a non-function property.
        [color=blue]
        > Many thanks for your views, I will use your advice![/color]

        You are welcome. And please read





        PointedEars

        Comment

        Working...