Posted By

elightbo on 02/12/09


Tagged

javascript png


Versions (?)

IE6 png lightweight js


 / Published in: JavaScript
 

Haven't tested this yet.

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

Report this snippet  

You need to login to post a comment.