Jump to content

PNG Handling (IE Only)


iyeru42

Recommended Posts

Normally IE 5.5 to 6 doesn't handle PNGs... I have a JavaScript code (shown below) but for my IE6, it doesn't work. Please help me.

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.  {  for(var i=0; i<document.images.length; i++)	 {	  if(document.images[i].className == "noAlpha") //This is where you can change the className		{  var imgpng = document.images[i]  var imgpngName = imgpng.src.toUpperCase()  if (imgpngName.substring(imgpngName.length-3, imgpngName.length) == "PNG")	 {  var imgpngID = (imgpng.id) ? "id='" + imgpng.id + "' " : ""  var imgpngClass = (imgpng.className) ? "class='" + imgpng.className + "' " : ""  var imgpngTitle = (imgpng.title) ? "title='" + imgpng.title + "' " : "title='" + imgpng.alt + "' "  var imgpngStyle = "display:inline-block;" + imgpng.style.cssText  if (imgpng.align == "left"){ imgpngStyle = "float:left;" + imgpngStyle }  if (imgpng.align == "right"){ imgpngStyle = "float:right;" + imgpngStyle }  if (imgpng.parentElement.href){ imgpngStyle = "cursor:hand;" + imgpngStyle }  var strNewHTML = "<span " + imgpngID + imgpngClass + imgpngTitle  + " style=\"" + "width:" + imgpng.width + "px; height:" + imgpng.height + "px;" + imgpngStyle + ";"	 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"  + "(src=\'" + imgpng.src + "\', sizingMethod='scale');\"></span>"  imgpng.outerHTML = strNewHTML  i = i-1	 }	 }  }}if( window.attachEvent ){window.attachEvent("onload", correctPNG);}

Please Note: This script ONLY works on Windows Operating Systems running Internet Explorer 5.5 or higher. Firefox/Netscape/Opera/IE7 users have no need for this script, because A.) It doesn't work in those browsers and B.) They already handle PNGs correctly.Also Note: Setting the code BBCode to codebox causes everything in it to be italics. Another note, I couldn't search in this forum for PNG since IPB limits the minimum number of characters for searching to four.

Link to comment
Share on other sites

Wait wait wait... you're saying this JavaScript enables PNG alpha transparency in IE5.5 and IE6?That would be priceless if it works (I'll test it later...). Where did you got it from? Is it yours? If so, then you're one heck of a JavaScript master :) .

Link to comment
Share on other sites

Well, I can't use this though:
<public:component><public:attach event="onpropertychange" onevent="propertyChanged()" /><script>var supported = /MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32";var realSrc;var blankSrc = "blank.gif";if (supported) fixImage();function propertyChanged() {   if (!supported) return;   var pName = event.propertyName;   if (pName != "src") return;   // if not set to blank   if ( ! new RegExp(blankSrc).test(src))      fixImage();};function fixImage() {   // get src   var src = element.src;   // check for real change   if (src == realSrc) {      element.src = blankSrc;      return;   }   if ( ! new RegExp(blankSrc).test(src)) {      // backup old src      realSrc = src;   }   // test for png   if ( /\.png$/.test( realSrc.toLowerCase() ) ) {      // set blank image      element.src = blankSrc;      // set filter      element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +                                     src + "',sizingMethod='scale')";   }   else {      // remove filter      element.runtimeStyle.filter = "";   }}</script></public:component>

And even if it did work, what If I wasn't using Win32, and I was using some other form of Windows? (Like that made for x64 processors.)

Link to comment
Share on other sites

Nevermind people. I know why it doesn't work. NONE of these work on Background images. So I guess I'll just have to add a white BG to my PNG images... :)But this works for the IMG tags. My code above apparently didn't if you don't have aclass named noAlpha.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...