Search the web
Sign In
New User? Sign Up
wdf-dom · JavaScript W3C DOM implementation in the
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Serious IE 6/Win Background Image No-Cacheing Problem   Message List  
Reply | Forward Message #4062 of 5642 |
Hi. Microsoft Internet Explorer 6/Windows refuses to cache the
background images of dynamically-created DIVs with
mouseover/mouseout rollover effects that change the
background image.

My code works for IE 5/Win+Mac, as well as Netscape
7/6/4/Win+Mac, but with IE 6/Win, the background images are
loaded but not cached even after I've tried pre-loading them with
new Image(). Each and every mouseover/mouseout event
results in a connection to the webserver. The 2 images are
small (4 KB each), but because multiple DIVs use them as
background images, the load time is totally unacceptable. Here
is the relevant code snippet:

var w = 150
var h = 25
var offimg = new Image(w,h)
offimg.src = 'blueMarble.jpg'
var onimg = new Image(w,h)
onimg.src = 'redMarble.jpg'
...

// W3C DOM-1

var M =
document.appendChild(document.body.createElement('div'))
...
var I = M.appendChild(document.body.createElement('div'))
I.style.backgroundImage = 'url(' + offimg + ')'
I.onmouseover = onLinkW
I.onmouseout = offLinkW
...
function offLinkW()
...
this.style.backgroundImage = 'url(' + onimg.src + ')'
...
function offLinkW()
...
this.style.backgroundImage = 'url(' + offimg.src + ')'
...

I've already tried hardcoding the images in a non-displaying DIV:

<div style='display:none'>
<img src='blueMarble.jpg' width='150' height='25'>
<img src='redMarble.jpg' width='150' height='25'>
</div>

... but the images are still not cached by IE 6/Win. My image link
paths are all relative, not absolute btw.

Is there something wrong with my code? Is there a real
workaround? Or is this an example of when sometimes a bug is
just a bug and not a feature?

TIA

REFERENCES

http://msdn.microsoft.com/workshop/author/dhtml/reference/pro
perties/backgroundimage.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;319546
("When you run Internet Explorer, the Internet Explorer cache is
not used as you expect when you run innerHTML code to insert
the same image multiple times. .... RESOLUTION Preload the
image in a DIV element with the display:none attribute[.] ....
STATUS This behavior is by design.")

http://dhtmlnirvana.com/content/blog.html
("Preloading Hover States Bug: Zeldman in his essential
sections describes a technique for preloading background
images in standards based browsers with the hover state. Great
idea in practice, however it falls short in its implementation. The
problem is that Internet Explorer 6 does not preload the hover
state and instead of using the background image from the
cache, does a hard reload of the image, making for sloppy
rollover effects. / If you have Internet Explorer 6 and a slow
modem (56k or less) the problem is quite evident at Zeldmans
home page. Use larger images and the problem is exaggerated
further. / To overcome the problem, hard code the image in the
body section of the document. This forces Internet Explorer 6 to
use the image from the cache and you end with a nice smooth
rollover. To hide the image used in the body section, simply set
its display to none. More information on this technique in the next
edition of the newsletter.")

http://www.netmechanic.com/news/vol6/javascript_no1.htm
("A JavaScript bug in recent versions (5 and 6) of Internet
Explorer may cause problems with JavaScript rollovers. The
browser ignores the images saved in the local cache file and
instead requests the image from the server each time a visitor
moves the mouse over the image. .... When you use an absolute
image path inside your JavaScript rollover code, Explorer ignores
the cached copy and requests the file from the browser each
time it's needed.")






Wed Jun 11, 2003 6:27 pm

joemacman
Offline Offline
Send Email Send Email

Forward
Message #4062 of 5642 |
Expand Messages Author Sort by Date

Hi. Microsoft Internet Explorer 6/Windows refuses to cache the background images of dynamically-created DIVs with mouseover/mouseout rollover effects that...
joemacman
Offline Send Email
Jun 11, 2003
6:42 pm

Hi, Sounds like an annoying bug.. Have you tries to simply have two different DIVs with one image on each and just making one of the DIVs visible at a time and...
Thomas Backlund
Thomas.Backlund@...
Send Email
Jun 12, 2003
8:28 am

A most annoying and major defect of IE 6/Win imho. I really don't want to be forced to using backgroundColor and the 216 "websafe" colors. Thanks for the code...
joemacman
Offline Send Email
Jun 12, 2003
8:22 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help