intelliproject logo

Location: Scripting language - JavaScript    License: The Intelliproject Open License (IPOL)

Transparent PNGs in Internet Explorer 6

Posted by Silviu Caragea

Describe how to display transparent PNGs in Internet Explorer 6

Skill: Beginner

Posted: 13/10/2008

Views: 262

Rating: 4.00 /5

Popularity: 1.20

Sign Up to vote for this article

Introduction

In IE 6 if your webpage contains an image that has a transparent background in Portable Network Graphics (PNG) format, the image background may appear to be gray rather than transparent.

What is alpha-transparency?

GIF files are only capable of displaying a pixel as either completely transparent or completely opaque: this is known as binary transparency.

PNGs can contains alpha layers,so parts of an image can be partially transparent. You can specify a level of transparency from 0 to 255.

All popular browsers can display PNGs transparent background , but not IE6 and previous versions of IE.

To fix this issue on Internet Explorer 6 you can use the following Javascript code :

  • function detectBrowserIE6() – this function detect if your browser is Internet Explorer 6
  • function LoadPngTransparency() – apply to all PNGs loaded in your page the AlphaImageLoader filter.

This Microsoft proprietary alpha image loader filter is often used to work around the missing 32-bit PNG alpha transparency (24-bit + 8-bit alpha channel). The AlphaImageLoader filter is a "procedural surface", it displays an image "between the object background and content" .

Save the above two functions in a file called "transparentPNG.js" and then add the following code in your HEAD section from html.

After that create a GIF image (1px x 1px) called "1px_square.gif". This image will be displayed "between the object background and content".

That’s all. When your page will be loaded, this script will apply the AlphaImageLoader filter to all your PNGs file in that page.

You can download the source code to see this little script in action.

License

This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)

About the author

Silviu Caragea

Silviu Caragea is the Founder, Administrator and Chief Editor who wrote and runs The IntelliProject.

He's been programming since 2000 and now he's student at The Faculty of Economic Cybernetics, Statistics and Informatics from Bucharest. In the same time he's working as software developer at Cratima Software, a Romanian software and web design company that activates both on the local and foreign market, providing its customers with software development services, internet and intranet solutions, web design, graphic design and IT consultancy.

His programming experience includes:
- C,C++, Visual C++(Win32 API, MFC, ADO, STL, DAO, ODBC, ATL, COM, DirectShow, DirectDraw, WTL)
- Open Source libraries :CURL & Boost
- HTML, CSS
- Java (SE,ME)
- JavaScript, Ajax, Google Web Toolkit (GWT)
- Php, MySQL
-Oracle, PL SQL
- C# .NET
-Objective C, IPhone SDK, Cocoa

Location: Romania
Ocupation: Software Engineer
Home page: http://www.intelliproject.net

Sign up to post message on the article message board!