views:

577

answers:

1

I'm trying to work out how to get the onabort event of an image element to work. From reading the docs it's meant to fire when a loading page is stopped either from clicking the stop button or firing the stop event.

I can get the following code snippet to work in IE but not in any of the other browsers. What am I doing wrong?

<html>
<head>
</head>
<body>
    <script type="text/javascript">
     function load(e) {
      alert('img loaded');
     }
     function onaborthandle() {
      alert('on abort hadnle');
     }

     function abort() {
      if (window.stop) {
       window.stop();
      }
      else {
       document.execCommand("Stop", false);
      }
     }
    </script>

    <img id="testimg" onabort="alert('abort inline');" />

    <script type="text/javascript">
     var img = document.getElementById('testimg');

     img.onload = load;
     img.src = 'http://sstatic.net/so/img/logo.png';

     abort();
    </script>
</body>
</html>
A: 

nothing is wrong, onabort and onerror are not supported in ff, and apparently in chrome too. although I read somewhere that the event will not work on local system files, but on files hosted on the web, not sure about it.

Kheu
I have the onerror event hooked up and it does fire when the image src doesn't exist. It's just the onabort that doesn't work. I've researched a bit further and it does appear that onabort is IE only :(
Alex
im not really sure WHY you need the onabort event, but maybe you can find another way to do the same thing?
Kheu
The problem I was trying to solve was not requesting an image which returns a session cookie while it is already downloading. I solved the problem in a different way by dropping any attempts to download the image if it was downloaded in the last 10 seconds. It's not perfect but it works :)
Alex