PNG FIX using Javascript for Transparent Images on IE5.5 and IE6 Browsers

Share this Article :


If we are working on Cross browser Applications, One of the Challenge is work on PNG Transparancy for IE6 and IE5.5 ..

For those Who are looking to Fix up this issue as quick as possible , Here is a Simple JS File which Does the Magic for the PNG Files on the Webpage after Page Load..

 
/*  Place the Following Code in a  .js  file  and  Call  it  on the bottom of the page */
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
      }
   }
}

More information can be found on the authors website, You can see a Demo which is written so beautifully which explains the problem as well as the solution

PNG TEST

Hope You will Love it and Guess what It will definitely Solves your Purpose ..

Happy Coding !!

Written by adrevol

{adrevol has written 91 posts on ITTreats.com . See all posts by }


Leave a Reply