HTML: IE file submission

I’ve been bumping up against an interesting bug in Internet Explorer recently, and, having just found the solution, thought I’d share it with you.

The problem is that in Internet Explorer (tested 7 & 8), when your document is in quirks mode, uploading a file sometimes just sends through the file name, without the actual body of the request. Put the document into standards mode, and it all works. It should be noted that this is when you’re dynamically setting up the elements used with JavaScript.

The cause? In quirks mode, the enctype attribute isn’t supported. So whilst setting “encType” on the form element to the correct “multipart/form-data” will indeed set this attribute, it won’t actually cause the upload to include the file. Instead, you need to set the encoding attribute to this value, too. It certainly doesn’t help that the MSDN article on the <input type=”file”> element tells you to set “enctype”, but makes no mention of “encoding”.

I couldn’t find any reference to this problem on the intertubes (although maybe I just didn’t look hard enough), so hopefully this will help someone.

Javascript: Print a single element

Sometimes, you’ll want to allow users the ability to print only a part of your page; for example, a table but not the various links around the page. It’s possible to use a printing stylesheet, but this can cause severe headaches when you need different parts printed at different times. Really, we want to be able to just say element.printElement(), and have it just work. That’s what the MooTools function below does. It’s loosely based around the concepts outlined at this website.

Element.implement({
  printElement: function(docTitle) {
    var strName = 'printer-' + (new Date()).getTime();
    var styles = [];
    $$('link[type=text/css]').each(function(style) {
      styles.push('<link rel="stylesheet" type="text/css" href="' + style.get('href') + '"/>');
    });
    var title = docTitle || document.title;
    var that = this.getParent();
    var iframe = new IFrame({
      name: strName,
      styles: {
        width: 1,
        height: 1,
        position: 'absolute',
        left: -9999
      },
      events: {
        load: function() {
          var doc = window.frames[strName].document,
              win = window.frames[strName];
          var f = function() {
            if (!doc.head) {
              f.delay(10);
              return;
            }
            // We need to delay printing so that styles are applied.
            (function() {
              doc.title = title;
              // IE7 won't let us adopt() here for some reason, and we can't do anything to the head.
              doc.body.innerHTML = styles.join('') + that.innerHTML;
              (function() {
                win.focus(); // IE needs the window to be focused.
                win.print();
              }).delay(100);
            }).delay(200);
          };
          f();
        }
      }
    }).inject($(document.body));
    (function() {
      iframe.dispose();
    }).delay(30000);
  }
});

Songs for the Cure 2010

Last year, I was proud to be part of the inaugural Indie Music Cancer Drive. Along with a whole lot of very talented artists, I contributed music to a compilation album, “Songs for the Cure”. All the proceeds from the sales of this album went to the American Cancer Society.

Songs for the Cure 2010

This year, I am once again contributing. I just finished work on the track I will be contributing, so I thought it high time I let everyone know about this. Josh Whelchel, the organiser of the drive (and a fantastic musician to boot), has set a target of $10,000 for this year. If you donate $25 or more, you receive a physical copy of the (two disc!) album; otherwise, you receive the album digitally.

Here’s the official media release:

Indie Music Cancer Drive to Release Songs for the Cure ’10 Album

Twenty-eight artists join together to raise money for the American Cancer Society and aim to raise $10,000.

Cincinnati, OH, January 24th, 2010. – The Indie Music Cancer Society will release it’s 2010 compilation, Songs for the Cure ’10 on March 1st, 2010 and forward 100% of all donations and profits to the American Cancer Society through its Relay for Life event held on April 23rd, 2010 at the University of Cincinnati. The album will feature music from over twenty-eight (28) diverse artists, including Select Start, big giant circles, Alec Holowka, Two Seconds Away, Jay Tholen, Josh Whelchel, Renee Winter, and others. The organization is currently accepting donations, and all donors of $25 or more before MARCH 1, 2010 will receive a free physical copy of the album. Supporters with $10 or more will receive a free digital copy. Genres represented include Pop, Rock, Alternative, Chiptunes, Instrumental, Opera, Classical, Avant-Garde, Jazz, Fusion, and many others. The organization raised over $6,000 for the event last year and is still forwarding profits from last year’s album, available on iTunes, Amazon, and others. A full list of artists can be found at the Songs for the Cure ’10 website at http://www.cancerdrive.org. The fundraiser aims to raise $10,000 by April 23rd, 2010, preceding a digital release of the album to iTunes, Amazon, CDBaby, and other retailers. Donations are accepted through http://www.cancerdrive.org.

For more information please contact:

JOSH WHELCHEL
(513) 549-2336
http://www.cancerdrive.org

So there you have it. And for good measure, here’s the promotional video: