IE6 PngFix in Javascript

As a web developer you will know just how much we all love hate Internet Explorer 6 – one of the most dreaded browsers and browser versions that still exists in the deep dark corners of the interwebs – and you will probably have figured out that it doesn’t play well with PNG images.

So here is how you can resolve this problem. It’s not as nice as an actual browser that can render PNG images natively, but it does work.

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters))
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id=’" + img.id + "’ " : ""
var imgClass = (img.className) ? "class=’" + img.className + "’ " : ""
var imgTitle = (img.title) ? "title=’" + img.title + "’ " : "title=’" + img.alt + "’ "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\’" + img.src + "\’, sizingMethod=’scale’);\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}


Share This Article

Related Posts

Comments

There are no comments on this entry.

Trackbacks

There are no trackbacks on this entry.

Add a Comment

Required

Required

Optional

Latest Domains

1. teledyne.com
(5 hours ago)
2. ngtechonology.com
(6 hours ago)
3. nonude.in
(7 hours ago)
4. spicyhunt.com
(13 hours ago)
5. whpromotions.co.uk
(16 hours ago)
6. seslihome.com
(17 hours ago)
7. sesliislam.com
(20 hours ago)
8. woopra.com
(1 day ago)
9. wapdam.com
(1 day ago)
10. 193.105.134.194
(1 day ago)

Services

PHP MySQL Apache Flash Air Java C++ Python