iyeru42 Posted September 11, 2006 Share Posted September 11, 2006 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 More sharing options...
boen_robot Posted September 11, 2006 Share Posted September 11, 2006 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 More sharing options...
iyeru42 Posted September 11, 2006 Author Share Posted September 11, 2006 No, it isn't mine, it's the_white_knight3's from http://www.fmods.com Link to comment Share on other sites More sharing options...
Webworldx Posted September 11, 2006 Share Posted September 11, 2006 Have you tried the old WebFX way?http://webfx.eae.net/dhtml/pngbehavior/pngbehavior.html Link to comment Share on other sites More sharing options...
iyeru42 Posted September 11, 2006 Author Share Posted September 11, 2006 Have you tried the old WebFX way?http://webfx.eae.net/dhtml/pngbehavior/pngbehavior.html 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 More sharing options...
iyeru42 Posted September 12, 2006 Author Share Posted September 12, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now