Posted By

luman on 06/04/07


Tagged

fix ie png patch


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

jonhenshaw
imbuez
basicmagic
vali29
heinz1959


Other PNG IE fix


 / Published in: JavaScript
 

URL: http://homepage.ntlworld.com/bobosola

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

Report this snippet  

You need to login to post a comment.