I was wanted to apply the transparent filter to the background images in a webpage. I used sleight.js to solve the Internet Explorer behaviour in making the PNG files transparent. But, this script lacked in processing the background images (like the images set for "background" attributes).
I tried to sort it out. Check the below self-documented JS script that loops thru the background images and applies the filter
<script>
// *************
// FIX : for the background images of th TD tag
// ***************
function fixBackgroundPng()
{
//Get all the TD's
var tgTags = document.getElementsByTagName("td");
if(tgTags == null) return;
//Loop thru the Td's and find whether
//Any PNG file is set as background
for(var c=0;c<tgTags.length;c++)
var src = tgTags[c].background;
if(src.match(/\.png$/i)!=null) {
//If any PNG file is set as background
//Apply the filter in the same way
//How sleight.js does.
var h,w;
if(tgTags[c].height){ h= tgTags[c].height; tgTags[c].style.height = h + "px"; }
if(tgTags[c].width){ w= tgTags[c].width; tgTags[c].style.width = w + "px"; }
tgTags[c].style.filter
= "progid:DXImageTransform.Microsoft.AlphaImageLoader
(src='" + src + "', sizingMethod='scale')";
tgTags[c].background = "x.gif";
}
}
}
//Attach funtion with OnLoad event, so that all the PNGs
//will be processed while the page loads.
if (navigator.platform == "Win32" &&
navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
window.attachEvent("onload",fixBackgroundPng);
}
>
Sorry dudes, I can't format the code more perfectly, let me know if you have any issues while using this code.