Friday, May 08, 2009

How to fix the PNG image transperancy problem in IE?

PNG image transparency not working in IE 6.0 or less than 6.0

If you want to use the transperancy then use the following script in your html. Call this function in the image onLoad function....

SCRIPT:
--------

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function fixPNG(myImage)
{
if ((version >= 5.5) && (version < 7) && (document.body.filters))
{
var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
var imgTitle = (myImage.title) ?
"title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
var imgStyle = "display:inline-block;" + myImage.style.cssText
var strNewHTML = "+ " style=\"" + "width:" + myImage.width
+ "px; height:" + myImage.height
+ "px;" + imgStyle + ";"
+ "filterrogidXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\">
"
myImage.outerHTML = strNewHTML
}
}

------------------------

For example, if you use the test.png file then the code like this...

img src="http://www.blogger.com/test.png" onload="fixPNG(this)"

No comments:

Post a Comment