force image load

Discussion in 'HTML & Website Design' started by davidcarlson, Feb 24, 2009.

  1. #1
    Is there a way to force a browser to download an image when it opens a page, that isn't included in a page?
    I have a mouseover function with javascript that causes the image to appear but I don't want a delay so I need the image to load beforehand.

    Any help is appreciated.
     
    davidcarlson, Feb 24, 2009 IP
  2. diligenthost

    diligenthost Peon

    Messages:
    685
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If it's an image rollover, doing this using CSS might be better for you. Doing it this way, the rollover only uses 1 image, instead of 2, meaning it wouldn't have to load a 2nd image. If this is what you need let me know and I can give you the info or find a link with it.
     
    diligenthost, Feb 24, 2009 IP
  3. DGK

    DGK Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If i understand you right use in the head section something like:

     
    <script language="javascript">
      var im = new image();
      im.src = 'somepath/somefilename';
    </script>
    
    HTML:
    This will force the browser to pre-load the image into memory :)
     
    DGK, Feb 25, 2009 IP
  4. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #4
    Kerosene, Feb 25, 2009 IP
  5. davidcarlson

    davidcarlson Guest

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's actually an OnClick function; I guess I will look into the CSS way of doing it. thanks for your help.
     
    davidcarlson, Mar 1, 2009 IP
  6. davidcarlson

    davidcarlson Guest

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So I decided to use javascript because my page involves multiple thumbnails that cause a full image to load.

    I have the following inside the <head> tags:
    <script language="javascript">
    var im = new image();
    im.src = 'image.jpg';
    </script>

    And I replaced, in the body of my page:
    onMouseDown="document.images.Pic.src='image.jpg'"
    with
    onMouseDown="document.images.Pic.src=im.src"
    (This code is inside a <span> tag that spans the thumbnail.)

    For some reason this isn't working. It was before, but there was a lag. Now the image doesn't load at all. I'm wondering if it isn't a code issue (I'm not very experienced with java).

    thanks again
     
    davidcarlson, Mar 2, 2009 IP
  7. davidcarlson

    davidcarlson Guest

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Any ideas?
     
    davidcarlson, Mar 6, 2009 IP