+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Senior Member quantass's Avatar
    Join Date
    Feb 2002
    Location
    Superstring Brane #2
    Posts
    579

    JAVASCRIPT - How do i abort an Image?

    I would like to abort a loading <IMG>. I've tried fireEvent to throw an "onabort", which does occur however the <IMG> clearly completes loading totally disregarding the onabort event. How do i "abort" a loading in image in Javascript?

    I've also tried setting .src="" though this creates a onerror message which Im trying to avoid.

  2. #2
    Senior Member CompGeek01's Avatar
    Join Date
    Aug 2002
    Location
    Next to an XServe Cluster
    Posts
    938
    I tried the following, which I found through Google. However, it didn't work. Honestly I've never even heard of this and I don't know why you'd really need to use it. I'm sure it must have some application. It sounds as if you don't want to notify the user that they've canceled the image..more that you want to just cancel the image altogether, which is it?

    Code:
    <HTML>
    <HEAD> 
    <TITLE>The onAbort Event Handler of the Image Object</TITLE> 
    <SCRIPT LANGUAGE = "JavaScript"> 
    function ImageAborted() { 
         if (window.confirm("The image is not loaded completely. Continue loading?")) 
         {
              document.images[0].src = "Dvc.jpg"
         }
    } 
    </SCRIPT> 
    </HEAD> 
    <BODY>
    <CENTER><H1>A Demonstration of onAbort with a Huge Image</H1></CENTER> 
    <CENTER>
    <IMG SRC="Dvc.jpg" onAbort="ImageAborted()">
    </CENTER><P>
    </BODY>
    </HTML>
    Live by it: RunDll32 advpack.dll,LaunchINFSection %windir%\INF\msmsgs.inf,BLC.Remove

  3. #3
    Senior Member ScaryBinary's Avatar
    Join Date
    Mar 2000
    Location
    Temporary Internet Files
    Posts
    741
    How do you know when an image should be aborted? If you know you're going to abort it ahead of time, then why load it? I'm guessing here that the image starts preloading, but you want to cancel it under some certain condition, or maybe some user input or something?

    DevGuru says this regarding images and aborting them:
    The onAbort event handler is used to execute certain JavaScript code whenever an abort event occurs, such as when the user stops the loading of an image by clicking a link or a Stop button.
    Just curious.

    I dug into the deep, dark world of javascript events, and couldn't find anything that would actually cause an image to stop loading (other than the user clicking the "Stop" button on his browser or following a link, but those would stop all images {i think} from loading, not just a particular one) ... only various ways to invoke the onAbort handler, which won't necessarily abort the image.

    Sorry.

  4. #4
    Senior Member ScaryBinary's Avatar
    Join Date
    Mar 2000
    Location
    Temporary Internet Files
    Posts
    741
    Just thought of this, might be worth a shot (success not guaranteed! ).

    If you are creating the images in javascript, like
    Code:
    myImage = new Image();
    myImage.src = "myimage.gif";
    then you might try just deleting it when you need to like
    Code:
    delete myImage;
    Not sure what will happen if the image happens to be loading at the time - if you'll get an error or what - but the "delete" keyword is indeed used for deleting javascript objects...

    See DevGuru (Scroll down a bit for the delete operator).

  5. #5
    Senior Member quantass's Avatar
    Join Date
    Feb 2002
    Location
    Superstring Brane #2
    Posts
    579
    Thanks for the info. Yes indeed I am trying to abort a downloading unseen image. I'm trying to make my own quick and dirty remote assistance app via javascript and IMG objects and if the user attempts to refresh the screen i want to abort all current dloading images.

Bookmarks

Posting Permissions

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







New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke