Posted By

iTony on 02/28/07


Tagged

javascript ie png ie6 ie5 transparacy


Versions (?)

Who likes this?

23 people have marked this snippet as a favorite

jonhenshaw
luman
nicolaspar
basicmagic
gbvb
luckylisbon
m0rris
hudge
vali29
yetanother
Baris
SpinZ
hans
rubensarrio
andyweb
jeroldan
ozenyx
eivind
seanpowell
claudiowebdesign
aegony
hobbyman
dayseye49


Correct the transparacy of PNG in IE5 and IE6


 / Published in: JavaScript
 

In IE5 and IE6 the transparancy in PNG images won't happen at all, so this would fix it. This might come really useful while we are in the era of switching to better standard-friendly browsers.

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

Report this snippet  

You need to login to post a comment.