Public paste
hiero
By: daveyw | Date: Nov 17 2006 19:05 | Format: None | Expires: never | Size: 1.49 KB | Hits: 1450

  1. <script language="JavaScript">
  2. function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
  3. {
  4.    var arVersion = navigator.appVersion.split("MSIE")
  5.    var version = parseFloat(arVersion[1])
  6.    if ((version >= 5.5) && (document.body.filters))
  7.    {
  8.       for(var i=0; i<document.images.length; i++)
  9.       {
  10.          var img = document.images[i]
  11.          var imgName = img.src.toUpperCase()
  12.          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
  13.          {
  14.             var imgID = (img.id) ? "id='" + img.id + "' " : ""
  15.             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  16.             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  17.             var imgStyle = "display:inline-block;" + img.style.cssText
  18.             if (img.align == "left") imgStyle = "float:left;" + imgStyle
  19.             if (img.align == "right") imgStyle = "float:right;" + imgStyle
  20.             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
  21.             var strNewHTML = "<span " + imgID + imgClass + imgTitle
  22.             + " style="" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  23.             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  24.             + "(src='" + img.src + "', sizingMethod='scale');"></span>"
  25.             img.outerHTML = strNewHTML
  26.             i = i-1
  27.          }
  28.       }
  29.    }    
  30. }
  31. window.attachEvent("onload", correctPNG);
  32. </script>