pngfix.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. Correctly handle PNG transparency in Win IE 5.5 & 6.
  3. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
  4. Use in <HEAD> with DEFER keyword wrapped in conditional comments:
  5. <!--[if lt IE 7]>
  6. <script defer type="text/javascript" src="pngfix.js"></script>
  7. <![endif]-->
  8. */
  9. var arVersion = navigator.appVersion.split("MSIE")
  10. var version = parseFloat(arVersion[1])
  11. if ((version >= 5.5) && (document.body.filters))
  12. {
  13. for(var i=0; i<document.images.length; i++)
  14. {
  15. var img = document.images[i]
  16. var imgName = img.src.toUpperCase()
  17. if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
  18. {
  19. var imgID = (img.id) ? "id='" + img.id + "' " : ""
  20. var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  21. var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  22. var imgStyle = "display:inline-block;" + img.style.cssText
  23. if (img.align == "left") imgStyle = "float:left;" + imgStyle
  24. if (img.align == "right") imgStyle = "float:right;" + imgStyle
  25. if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
  26. var strNewHTML = "<span " + imgID + imgClass + imgTitle
  27. + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  28. + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  29. + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
  30. img.outerHTML = strNewHTML
  31. i = i-1
  32. }
  33. }
  34. }