I am using the following code to fix PNG issue for IE6 (yes, we do have some visitors using IE6 :( ) ... the code seems to replace .png images with the blank image but then doesn't seem to run the filter properly ... any ideas why it could be failing? Thanks
var blank = new Image();
blank.src = 'img/blank.gif';
$(document).ready(function() {
var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
if (badBrowser) {
//alert('bad browser');
// get all pngs on page
$('img[src$=".png"]').each(function() {
if (!this.complete) {
this.onload = function() { fixPng(this) };
} else {
fixPng(this);
}
});
}
});
function fixPng(png) {
// get src
var src = png.src;
// set width and height
if (!png.style.width) { png.style.width = $(png).width(); }
if (!png.style.height) { png.style.height = $(png).height(); }
// replace by blank image
png.onload = function() { };
png.src = blank.src;
// set filter (display original image)
png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}
One possible actual answer for you, after all the comments saying not to bother doing anything:
Most of the remaining IE6 users are in corporates that just can't upgrade for one reason or another.
The may not be able to upgrade, but most of them are well aware of the major security issues that IE6 presents, and do try to mitigate the risks as much as possible.
One key thing that can be done to mitigate the IE6 risk is to disable the browser from running ActiveX, at least for sites on the external internet (activeX plugins on their internal intranet sites are often one of the reasons they can't upgrade).
You'll note that the filter
style uses ActiveX to do its magic.
Therefore, if ActiveX is disabled, it means that filter
styles won't work. This will break your pngfix. (It also breaks a lot of other stuff, including most Ajax code, so these users will have a pretty broken internet experience generally).
Its worth re-iterating that for IE6 users with ActiveX switched off, there is no other work-around for the PNG bug. If you've got users in this position then the only way around it is to go back to 2001 and use GIFs instead.
You could try some of the other png fix scripts out there - there are a number of them, and I know some worked better than others -- but at the end of the day I'll go back to my original comment and recommend just leaving the graphic rendering broken for IE6 users. Their internet experience will be broken enough anyway that if a site is usable at all it's a bonus; a few rendering glitches won't put them off.