Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Location
    brooklyn
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Why does this script fail only in safari?

    The javascript works with IE mac and PC, and Mozilla on PC.
    I can't find anyone who has documented quirks like this.

    Lend me a hand if you can. Thanks!

    ________________________


    Call this function on any page with images. It'll track whether they've loaded.

    function progress() {
    doneLoaded = 0;
    fraction = 100/(imgDivs.length + 1);
    for (var i = 0; i < document.images.length; i++) {
    img = document.images[i];
    // alert(i);
    if (img.complete == true) {
    alert('img#_' + i);
    doneLoaded += fraction;
    }
    }
    if (doneLoaded < 100) { setTimeout( "progress()", 100); }
    }

    ____________________________________

    see the script in action:
    http://www.the-coup.org/portfolio.html

    if all images aren't loaded, the script begins again from zero, but takes no time to catch up to where it left off.

    I use this in conjunction with another script that displays the progess of loading.

    script with alerts for debuggin
    http://www.the-coup.org/portfolio2.html
    (12 imgs, might loop twice, but not infinitely...promise)

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,949
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Maybe Safari doesn't support Image.complete property. Type this in the address bar to quickly verify:

    javascript:alert(typeof new Image().complete)

    It should alert boolean if supported and undefined if not.


    If indeed Safari doesn't support that property, try this solution:

    Drop the progress() function and just put this line outside a function:

    var fraction = 100/(imgDivs.length + 1);

    Then put an onload event handler in each of the <img> tags. I assume Safari supports onload, which it should.

    <img id="eshMD" class="imgDiv" style="left:40px;" src="images/eshMD.jpg" alt="Appeal" onload="doneLoaded+=fraction" />

    Then the script at the bottom should only call the unLoad('bar')

    <script language="JavaScript" type="text/javascript" >
    <!--
    unLoad('bar');
    //-->
    </script>

  • #3
    New to the CF scene
    Join Date
    May 2004
    Location
    brooklyn
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mozilla vs. safari

    Thanks. I didn't know I could test code in the address bar.

    Oddly enough, Safari returned boolean.

    It makes no sense. Safari will reach the first alert of my script, but won't return true. I don't own a mac anymore, which makes this difficult for me to troubleshoot. (and annoys my friends)

    I originally used <img onload="..."> as you suggested. But it's not standards compliant, so Mozilla won't do it. Onload is only legal with body and frameset.

    Img.complete was my mostly successful attempt to keep the code legit.

    If you have any other suggestions...

    Thanks again for digging into this.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,949
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Do you see any errors in the javascript console of safari?
    If the Debug menu of safari is not visible, read this JS FAQ (at the bottom part of the post) for instruction of turning it on.

  • #5
    New to the CF scene
    Join Date
    May 2004
    Location
    brooklyn
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    safari debug

    I don't have regular access to Safari.

    Can anyone out there run this code for errors?

    It'd be much appreciated...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •