Internet Explorer and the pjpeg MIME type

Posted on Friday, August 28th, 2009 under ,

stop_ie Did I mention that I hate Internet Explorer? Well, I do. I think that the web would be a much better place without Internet Explorer. Any Internet Explorer.

Today I’ve ran across another strange IE bug. When uploading a JPEG file, instead of the usual image/jpeg MIME as defined in RFC 1341, if the file is a progressive jpeg, then Internet Explorer sends a non standard MIME of image/pjpeg, which sucks, isn’t documented and breaks validation logic.


And since my code had something like:

# check mime type
mime, type = image.content_type.split( '/' )
if not ( mime == 'image' and type in ['jpeg', 'gif', 'png'] ):
    return False

…in it, well…you can imagine! So, if you *ever* check the MIME type of a file, remember that IE sometimes sends a image/pjpeg MIME.

No IE / No headaches ;)

Element.prototype in IE

Posted on Thursday, September 20th, 2007 under , ,

Some time ago, I needed to find out if a DOM element is a descendant of another. A simple and elegant way to accomplish this is:

/**
 *
 * @param mixed granpa
 *
 */
Element.prototype.isDescendantOf = function( granpa ) {
	if ( typeof( granpa ) == 'string' ) {
		granpa = document.getElementById( granpa );
	}
	if ( !granpa ) {
		return false;
	}
	child = this;
	do {
		if (child == granpa ) {
			return true;
		}
		child = child.parentNode;
	}
	while ( child );
	return false;
}

…and afterwards…

var foo = document.getElementById( 'foo' );
var bar = document.getElementById( 'bar' );
if ( foo.isDescendantOf( bar ) ) {
	/* whatever */
}

Cool, isn’t it? Keep reading»