I have created a script for the CSS media types checking/detection. You may use it for free for any purposes (non-commercial and also commercial). It's available for download at the end of this page (current version: 15-apr-2009).
If you need to check/detect the current CSS medium - for example if you wish to add some page content suitable only for some media types - this script may help you. This script:
does NOT require any CSS nor (X)HTML changes - it's enough to add the script using a <script> tag - see an example below
works properly during page loading and when page is loaded - it has a solution for the KHTML layout engine (Konqueror is KHTML-based) allowing to check the media types before the whole page is loaded (and before all CSS style sheets are applied)
works both with HTML and XHTML languages - it has been tested with HTML 4.01 Strict and XHTML 1.1 (with an "application/xhtml+xml" MIME type HTTP header for all capable browsers - i.e. for all tested browsers except Internet Explorer and Opera 7.2x)
does NOT disable the Opera's Small-Screen Rendering technology when asking about the 'handheld' media type in the Opera's mobile browsers. Because a DOM element used for testing is created and destroyed dynamically, it has no impact on the Opera's Small-Screen Rendering technology - there is no static element or style sheet with the 'handheld' media type active. You can test this here: Opera Mini Simulator (Notice: a "Mobile view" option is off by default)
works properly with relatively old browsers - it uses the widely recognized 'color' CSS property for testing. It has also a workaround for Opera < 9.5 bug, which causes losing the CSS style sheet 'body' settings randomly when some weird conditions are met together (script uses the 'currentStyle' property during page loading (but not when page is loaded) on an element contained inside the 'body' (but not 'head') section, the CSS style sheet contains style for the '*' class, page is loaded through the HTTP (but not FILE) protocol, user has refreshed the page (F5)). The script has also a workaround for Opera 7.2x, allowing it to add new styles dynamically with success.
Tested and works (during page loading and when page is loaded) with:
Internet Explorer (Trident): 5.01, 5.55, 6.0, 7.0, 8.0
Contact: If you have any notices, improvements to this script or if you want to report a bug, you may find the contact information inside the script file. Please contact me in the matter of this script only, and don't ask me for help. I'm a very busy person, so I will have to ignore e-mails with help requests.