Img on error works in safari but not firefox,(leopard) what can I doto fix that.

Discussion in 'Javascript' started by anne001, Nov 28, 2007.

  1. anne001

    anne001 Guest

    I am using Leopard

    I found this code and am testing it as is. It works fine on safari
    3.0.4 (gives an alert and then changes the missing picture icon to an
    actual picture images/2.jpg), but not at all on firefox 2.0.0.10, no
    alert, no swap of image (on Leopard). I am testing this because on a
    larger script I put a missing image on purpose, firefox triggered the
    "onload" fx even though the image was not there and the image shown
    was the missing image icon!!? that is strange. On that larger script,
    firefox did open an alert window, so that is not the problem?

    What else can I use which would work on all browsers? I need the
    scripting part mostly so I can preload and check 100s of pictures to
    make sure they were all found.

    I checked it in jslint, which did not like the inline part, but
    removing it did not change anything

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Checking files</title>
    <script type="text/javascript">
    var imgsrc = 'picture1.gif';
    var img = new Image();

    img.onerror = function (evt) {
    alert(this.src + " can't be loaded.");
    };
    img.onload = function (evt) {
    alert(this.src + " is loaded.");
    };

    img.src = imgsrc;
    </script>
    </head>

    <body>
    <img src="p1.gif" onerror="this.onerror=null;this.src='images/
    2.jpg';">

    </body>
    </html>
    anne001, Nov 28, 2007
    #1
    1. Advertising

  2. anne001

    VK Guest

    Re: Img on error works in safari but not firefox,(leopard) what can Ido to fix that.

    On Nov 28, 9:42 pm, anne001 <> wrote:
    > I am using Leopard
    >
    > I found this code and am testing it as is. It works fine on safari
    > 3.0.4 (gives an alert and then changes the missing picture icon to an
    > actual picture images/2.jpg), but not at all on firefox 2.0.0.10, no
    > alert, no swap of image (on Leopard).


    In Firefox imgObject.onerror handler is intentionally killed in any
    form, even for hardcoded in the source <img> elements (internal
    security exception raised) - maybe to prevent any possibility of
    content sniffing or I don't know. AFAICT nothing you can do about it.
    Either screw on Firefox, or move your logic server-side which is
    suggested: so get directory check results from server script over some
    ajaxoid.
    VK, Nov 28, 2007
    #2
    1. Advertising

  3. anne001

    anne001 Guest

    Re: Img on error works in safari but not firefox,(leopard) what can Ido to fix that.

    We would like to be compatible to most browsers. So I am interested in
    the ajaxoid.

    I am new to webprogramming (not to programming). I have several books
    on ajax. Could you give me a few keywords to look for?

    Right now I don't have a server script. I will have a serverscript to
    receive the
    user responses (sent through a form post). How would my html interact
    with a serverscript on loading the images?

    " get directory check results from server script over some ajaxoid"
    anne001, Nov 28, 2007
    #3
  4. anne001

    VK Guest

    Re: Img on error works in safari but not firefox,(leopard) what can Ido to fix that.

    On Nov 28, 10:25 pm, anne001 <> wrote:
    > We would like to be compatible to most browsers. So I am interested in
    > the ajaxoid.
    >
    > I am new to webprogramming (not to programming). I have several books
    > on ajax. Could you give me a few keywords to look for?
    >
    > Right now I don't have a server script. I will have a serverscript to
    > receive the
    > user responses (sent through a form post). How would my html interact
    > with a serverscript on loading the images?
    >
    > " get directory check results from server script over some ajaxoid"


    I am actually surprised myself but this demo is pretty explicit:

    <html>
    <head>
    <title>Demo</title>
    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <p><img src="foobar.gif" onerror="alert('error')"
    onload="alert('Loaded')"></p>
    </body>
    </html>

    If foobar.gif doesn't exist then onerror handling is silently
    supressed in Firefox. Someone in Gecko team has chosen a "simple
    solution" for the problem.

    So your only option would be then to try to use XmlHttpRequest like
    the one on www.ajaxtoolbox.com to see if you can catch 404 Not found
    responses
    But if XmlHttpRequest even allowed to request binary data? I don't
    remember.
    VK, Nov 28, 2007
    #4
  5. anne001

    anne001 Guest

    Re: Img on error works in safari but not firefox,(leopard) what can Ido to fix that.

    Thank you so much for your help
    anne001, Nov 28, 2007
    #5
  6. Re: Img on error works in safari but not firefox,(leopard) what canI do to fix that.

    anne001 wrote:
    > [...] What else can I use which would work on all browsers?


    It is an illusion to think that anything would work on all browsers.


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
    Thomas 'PointedEars' Lahn, Nov 29, 2007
    #6
  7. Re: Img on error works in safari but not firefox,(leopard) what canI do to fix that.

    anne001 wrote:
    > We would like to be compatible to most browsers. So I am interested in
    > the ajaxoid.


    To be compatible to most browsers, you will have to abandon the notion of
    the "ajaxoid".


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Nov 29, 2007
    #7
  8. Re: Img on error works in safari but not firefox,(leopard) what canI do to fix that.

    Randy Webb wrote:
    > Thomas 'PointedEars' Lahn said the following on 11/29/2007 4:51 PM:
    >> anne001 wrote:
    >>> We would like to be compatible to most browsers. So I am interested in
    >>> the ajaxoid.

    >> To be compatible to most browsers, you will have to abandon the notion of
    >> the "ajaxoid".

    >
    > Pure nonsense.


    It isn't. "Most" means the maximum possible coverage, and XHR ("the
    ajaxoid") is not even necessary here.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Nov 30, 2007
    #8
  9. Re: Img on error works in safari but not firefox,(leopard) what canI do to fix that.

    Randy Webb wrote:
    > Thomas 'PointedEars' Lahn said the following on 11/30/2007 12:48 PM:
    >> Randy Webb wrote:
    >>> Thomas 'PointedEars' Lahn said the following on 11/29/2007 4:51 PM:
    >>>> anne001 wrote:
    >>>>> We would like to be compatible to most browsers. So I am
    >>>>> interested in the ajaxoid.
    >>>> To be compatible to most browsers, you will have to abandon the
    >>>> notion of the "ajaxoid".
    >>> Pure nonsense.

    >> It isn't. "Most" means the maximum possible coverage, and XHR ("the
    >> ajaxoid") is not even necessary here.

    >
    > I didn't say it was necessary.


    So your reply was only for the sake of the argument?

    > I said the notion that to be compatible to "most browsers" means you have
    > to abandon AJAX is Pure Nonsense. The term for it is "graceful
    > degradation".


    Graceful degradation implies that there were cases were AJAX would not work.
    Abandoning AJAX would result in a solution that would be compatible in more
    cases than not abandoning it.


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
    Thomas 'PointedEars' Lahn, Dec 1, 2007
    #9
  10. Re: Img on error works in safari but not firefox,(leopard) what canI do to fix that.

    Randy Webb wrote:
    > Thomas 'PointedEars' Lahn said the following on 12/1/2007 5:38 AM:
    >> Randy Webb wrote:
    >>> I said the notion that to be compatible to "most browsers" means you have
    >>> to abandon AJAX is Pure Nonsense. The term for it is "graceful
    >>> degradation".

    >> Graceful degradation implies that there were cases were AJAX would not work.
    >> Abandoning AJAX would result in a solution that would be compatible in more
    >> cases than not abandoning it.

    >
    > Then why do you script at all?


    You misunderstand. What I addressed was the notion of "most compatible".


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Dec 1, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee
    Replies:
    22
    Views:
    1,117
    Tim Roberts
    Mar 21, 2006
  2. Xah Lee
    Replies:
    23
    Views:
    1,061
    Tim Roberts
    Mar 21, 2006
  3. David
    Replies:
    2
    Views:
    103
    Lasse Reichstein Nielsen
    Sep 21, 2003
  4. Xah Lee
    Replies:
    21
    Views:
    781
    Tim Roberts
    Mar 21, 2006
  5. Luke Venediger
    Replies:
    3
    Views:
    145
Loading...

Share This Page