Posted By

Hanek on 12/03/07


Tagged

fix png


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

vali29
basicmagic
juanluisrp
heinz1959
guo3823538
wirenaught


PNG Fix


 / Published in: JavaScript
 

This is not my script and I take no credit for it. Thanks to Bob Osola and his mentors.

IMPORTANT:dimensions of img must be declared !!

  1. *************** PLACE IN FILE *** pngfix.js *****************************
  2.  
  3. var arVersion = navigator.appVersion.split("MSIE")
  4. var version = parseFloat(arVersion[1])
  5.  
  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.  
  32. *************** PLACE IN HEAD ********************************************
  33.  
  34. <script language="JavaScript" type="text/javascript" src="scripts/pngfix.js"></script>
  35.  
  36. <!--[if lt IE 7]>
  37. <script defer type="text/javascript" src="scripts/pngfix.js"></script>
  38. <![endif]-->

Report this snippet  

You need to login to post a comment.