Introduction
Internet Explorer doesn�t support the alpha channel in PNG images. However
the fix is to use the "AlphaImageLoader" filter. This script replaces all PNG
images on the page with a blank image (blank.gif) and adds the
"AlphaImageLoader" filter with the original image source. The blank image is to
avoid the "broken image" picture to display above the filter. This script also
supports printing and changing the source image at runtime.
Source
var PNGimageArray = new Array();
var isPrinting = false;
var blankSrc = "blank.gif";
window.attachEvent("onbeforeprint", function () { beforePrint(); } );
window.attachEvent("onafterprint", function () { afterPrint(); } );
function addPngImage(element){
if (/\.png$/i.test(element.src)) {
fixImage(element);
element.attachEvent("onpropertychange", function ()
{ propertyChanged(); } );
PNGimageArray[PNGimageArray.length] = element;
}
}
function fixImage(element) {
element.runtimeStyle.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='" + element.src + "')";
element.src = blankSrc;
}
function propertyChanged() {
if (isPrinting) return;
var element = event.srcElement;
var pName = event.propertyName;
if (pName != "src") return;
if (!new RegExp(blankSrc).test(element.src))
fixImage(element);
}
function beforePrint() {
isPrinting = true;
var element;
for(var i = 0; i < PNGimageArray.length; i++){
element = PNGimageArray[i];
element.src = element.filters[0].src;
element.runtimeStyle.filter = "";
}
}
function afterPrint() {
isPrinting = false;
var element;
for(var i = 0; i < PNGimageArray.length; i++){
element = PNGimageArray[i];
fixImage(element);
}
}
Style that makes all images run the
addPngImage
function. I
use "expression" instead of "behavior" to avoid some security issues in Internet
Explorer.
<style type="text/css"> img { filter:expression(addPngImage(this)); }
</style>