home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 September / PCW08_DVD.ISO / _bin / __pngfix.js next >
Encoding:
JavaScript  |  2005-07-06  |  1.2 KB  |  29 lines

  1.  
  2. // Correctly handle PNG transparency in Win IE 5.5 or higher.
  3. // http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
  4.  
  5. function correctPNG() 
  6.    {
  7.    for(var i=0; i<document.images.length; i++)
  8.       {
  9.       var img = document.images[i]
  10.       var imgName = img.src.toUpperCase()
  11.       if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
  12.          {
  13.          var imgID = (img.id) ? "id='" + img.id + "' " : ""
  14.          var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  15.          var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  16.          var imgStyle = "display:inline-block;" + img.style.cssText 
  17.          if (img.align == "left") imgStyle = "float:left;" + imgStyle
  18.          if (img.align == "right") imgStyle = "float:right;" + imgStyle
  19.          if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle        
  20.          var strNewHTML = "<span " + imgID + imgClass + imgTitle
  21.          + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  22.          + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  23.          + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
  24.          img.outerHTML = strNewHTML
  25.          i = i-1
  26.          }
  27.       }
  28.    }
  29. window.attachEvent("onload", correctPNG);