A simple hack to detect if images are enabled:
Include the following in your HTML:
<img src="http://microsoft.com/nothing.gif"; onerror="alert('hello');"
style="position: absolute;top=-100px" />

If images are enabled, we waste microsoft's bandwidth for a bit (it
could be any nonexistent image file on any server, obviously), and the
browser executes the onerror function (which should do something more
sophisticated than alert; it could change your stylesheet, for
instance).
If images are not enabled, the function is not executed.
The style attribute is there just to hide the ugly red x in IE, but
setting it really invisible with display: none or visibility: hidden
tells the better browsers (Opera) not to bother getting the image, so
the error function never gets called.

This was tested in Firefox 2, IE 6, Opera 9, Safari 3

Using jQuery to insert the element, with
$('<img src="http://microsoft.com/nothing.gif"; onerror="somefunc()"  /
>').appendTo('body')
works as well.

Danny

Reply via email to