Transparent PNG backgrounds in IE6


OSNN Junior Addict
7 May 2008
The solution is well known when we're talking about plain <img> tags, but it's not that trivial when we put the image as a CSS background.
I didn't want to convert my background images to GIF, so I wrote this Javascript code:
window.onload = function()
	var elementIdentifiers = ['element_with_png_bg_ID', 'id2', 'id3'];
	for (var i in elementIdentifiers)
		var currentElement = document.getElementById(elementIdentifiers[i]);
		if (!currentElement) continue;
		var backgroundImage = currentElement.currentStyle['backgroundImage'];
		var backgroundImageUrl = backgroundImage.substring(5, backgroundImage.length-2);
		var filterString = "progid:DXImageTransform.Microsoft.AlphaImageLoader  (src='"+backgroundImageUrl+"', sizingMethod='scale')"; = 'none'; = filterString;

If you want the code to be executed only in IE6 and lower versions, use this conditional comment:
<!--[if lt IE 7.]>
<script defer type="text/javascript" src="iepngfix.js"></script>

Hope it helps...


OSNN Junior Addict
3 May 2008
You might also want to look at IE7/8.js for working around a lot of the design flaws in Internet Explorer.

I've put it on a few websites before, and it usually does the job fairly well for those poor IE users left in the world. I like to write pages as the markup is intended to be used, but IE doesn't make it easy, heh.

Members online

No members online now.

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Latest member