SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Los Angeles
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image preload script not working in IE?

    I have tried two image preload scripts and neither one seems to work in IE 6. I'm trying to do an image swap and in IE, when I mouseover the image, IE seems to connect to the server and load it everytime instead of caching it (this same image is even used multiple times on the page!) Both scripts work fine with Mozilla.

    Script 1 (standard Dreamweaver):
    Code:
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    Script 2: (got off this forum):
    Code:
    function doPreload() {
    	var imgRoot = "/images/";
    	var the_images = [
    		'pd2.gif',
    		'explore2.gif',
    		'games2.gif',
    		'shops2.gif',
    		'chat2.gif',
    		'mail2.gif',
    		'help2.gif',
    		'login2.gif',
    		'logout2.gif'
    		];
    	preloadImages(the_images, imgRoot);
    	}
    
    function preloadImages(arrImages, root) {
    	for(var i = 0; i < arrImages.length; i++) {
    		var img = new Image();
    		img.src = root + arrImages[i];
    		}
    	}
    I'm calling both from the body tag's onload:
    Code:
    <body onload="__whateverscript__">
    Any idea why IE doesn't like either of these?

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a common mis-conception about preloaders. Javascript preloaders only truly work when you use the JSObjects you've preloaded in your rollover script. It's not enough to load the images so that they wind up in your computer's cached files.

    You follow?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Los Angeles
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I've read on here, it would be something like:

    Code:
    image1 = new Image();
    image1.src = "image1.gif";
    However, I'm not sure how to integrate this into my rollover script which is:

    Code:
    function commentsOver(num) {
    document.getElementById('ctable_'+num).style.background='url(/images/blog_commentbtn_o.gif)';
    
    document.getElementById('ctxt_'+num).style.color="#FFFFFF";
    }
    
    function commentsOut(num) {
    document.getElementById('ctable_'+num).style.background='url(/images/blog_commentbtn.gif)';
    
    document.getElementById('ctxt_'+num).style.color="#000000";
    }
    Instead of saying:
    document.getElementById('ctable_'+num).style.background='url(/images/blog_commentbtn.gif)';

    Do I say:
    document.getElementById('ctable_'+num).style.background=image1;

    ???

    Thanks for the help!

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Close

    document.getElementById('ctable_'+num).style.background='url(' + image1.src + ')';
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Los Angeles
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, thanks...I'll give that a whirl tomorrow. Just out of curiousity, why does DreamWeaver write that script when it doesn't even work?

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because Dreamweaver is made by humans, and humans are fallible. I have no better suggestion than that
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •