Showing posts with label Javascript PNG Fix IE6 Alpha BackgroundImage. Show all posts
Showing posts with label Javascript PNG Fix IE6 Alpha BackgroundImage. Show all posts

Friday, 25 May 2007

Javascript Alpha Background PNG Fix IE6

Want to fix the background PNG 24 Alpha image of an element in IE6?

Here's how I do it

function FixIEPngBG(elmnt){
if ((navigator.appVersion.indexOf('MSIE 6')>-1) && (document.body.filters)){
bkg = (elmnt.background? elmnt.background : (elmnt.style.backgroundImage? elmnt.style.backgroundImage : elmnt.currentStyle.backgroundImage));
bkg=bkg.replace('url(', '');
bkg=bkg.replace(')', '');
while (bkg.indexOf('"')>-1){
bkg=bkg.replace('"', '');
}
elmnt.style.backgroundImage="url(images/blank.gif)"; // has to have a background image otherwise it wont be recognised on drag.
elmnt.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+bkg+"', sizingMethod='scale');";
}
}