Simple IE6 javascript detection

21 April 2011

So i came across an issue where i had to set the min-width and max-width of an element. Instead of doing hacky and highly demanding css + javascript tricks to fool ie6 into playing nicely. I decided to detect the ie6 client using javascript, and use the onload method to set the widths. Simple and effective (my weapon of choice):

if (!window.XMLHttpRequest) { //IE6- stuff }

Less simple, but more robust:

(document.all && !window.opera && !window.XMLHttpRequest)

Similar to option one, potentially more sound as ie7 users can disable xml http requests:

(typeof document.addEventListener != 'function')

Seems a little hacky to me, as you are comparing it to a string, less boolean:

(typeof == "undefined")

I realise that I could have used the window.onresize listener, but i don’t want it to fire every time the width/height changes, id rather just set it on page load.

Matt Sain

Ramblings of a developer, designer and child subscribe

This blog is a public GitHub repository. If you find an error I will not be surprised... but if you fork and edit the blog and send me a pull request you'd be pretty awesome in my book.

Featured Repos