Fixing IE6 Alpha Layers

I generally prefer using PNGs to display images. They look better than GIFs because of the alpha-channel transparency, they compress much better than GIFs, and the color range is significantly wider and allows for smoother transitions and greater color precision. Plus, if you can live with the larger file size, they don’t have that lossy ghost pixelating of JPGs.

The problem is (what else?!) Internet Explorer, specifically version 6.X as it doesn’t support 24-bit PNG images with an alpha layer — which, of course, is what everyone wants on their web pages! So far, just about everybody and their grandmother creates “png.htc“, an IE-specific “behavior” component that fixes the alpha channel with an overlay. Then they apply a style class to the img (class="png") and then add a style to their stylesheet (.png { behavior: url('png.htc'); }).

Since I often use Firefox for development and testing, I sometimes forget to look for those easily overlookable details in IE. I still use png.htc files, but now I include a small script that searches the DOM for PNGs and applies the behavior style automatically, activated with an onload action (<body onLoad="fixBrowsers();">). It uses something called a Conditional Comment, a technique created by Microsoft, so it is sometimes praised and sometimes vilified.

Now I don’t have to remember to include the class for each image, and IE behaves the way I expect it to. Simple!

<script type="text/javascript">// <![CDATA[
function fixBrowsers() {
    /*@cc_on
    /*@if (@_jscript_version == 5.6)
      // add fix-alpha-layer behavior to all PNG images
      var array_images = document.getElementsByTagName("img");
      var array_pngs = new Array();
      var x;
      for (var i=0; i<array_images.length; i++) {
        x = array_images[i];
        if (array_images[i].src.substring(array_images[i].src.length -3,
            array_images[i].src.length) == “png”) {
          array_pngs.push(x);
        }
      }
      for (var x=0; x<array_pngs.length; x++) {
        array_pngs[x].style.behavior = ”url(’png.htc’)”;
      }
    /*@end
    @*/
  }
// ]]></script>

Now, if only the fixBrowsers function would magically fix everything that is wrong with IE6. Now THAT would be the most sought-after JavaScript function ever!!

Author’s Note: By now, given that even IE7 and IE8 are hopefully soon to be on the distant horizon, pretty much anything to do with IE6 is now hopelessly obsolete, as is my snippet of code above.

For any of you still interested in developing for IE5 and IE6 for some strange reason, check out the awesome IE7-JS library which pretty much does magically fix everything wrong with IE5 and IE6. (Thanks to Brett for pointing out that library.)



Windows Tip: Skipping the Recycle Bin

Ever had lots of large files on your Windows PC that you had to trash, but you wanted to skip putting them in the Recycle Bin and enduring the often lengthy process of emptying the Recycle Bin later?

Instead of dragging your files to the Recycle Bin or just hitting the Delete key, hold down the Shift key when you delete them — Select the files within Windows Explorer or My Computer, hold down the Shift key, and then right-click and select Delete from the Shortcut menu. This will bypass the Recycle Bin.

Just make sure you are certain of your delete action. Skipping the Recycle Bin greatly reduces your chance of recovery in the event of a mistake. While there are plenty of undelete utilities, they can often take hours to run and there is no guarantee that you will recover your lost data.

Author’s Note: This is one of those simple tips that most people seem to know about already, but is a great eye-opener to those few that haven’t heard of it yet!


Windows XP and ZIP Files

The Windows operating system has made a lot of advances in the last ten years — that admission a shocker coming from me, eh?! However, Microsoft has not been the innovator; rather it is the third-party companies that develop enhancements that have been the driving force behind the improvements.

For example, Norton Utilities was (and probably still is) the best system-repairing software utility around. Microsoft, seeing that, incorporated into its chkdsk utility (you know, the disk checking utility that starts running after Windows crashes and then insults you by claiming that you failed to shut down Windows properly) either a licensed version or a pretty fair emulation of an early version of Norton Disk Doctor.

Microsoft XP does the same thing with ZIP files, incorporating directly into the operating system a method of accessing the popular compression system developed by PKWare. XP goes one step further and treats ZIP files like any other folder. Great for novice users.

The problem is that, once you have have begun to gain both experience and a large number of ZIP files, it becomes a nuisance for two reasons: (1) searching through files with XP’s built-in Search function takes much longer because now searches automatically include all the files compressed within your ZIP files; and (2) viewing a directory with a large number of ZIP files can take a VERY long time to display as XP runs through each of those ZIP files before displaying the top directory. It becomes even worse when you have anti-virus software running!

I decided that I didn’t want XP to treat ZIP files like folders anymore. Here’s the method I used to turn it off:

Click Start, then Run. Type regsvr32 /u %windir%system32zipfldr.dll at the prompt and click OK. Reboot.

Want it back? Do the same thing; just leave out the “/u” in the command above and XP’s handling of ZIP files will be restored.