kamagra soft viagra rezeptfrei usa precio viagra en españa viagra rezeptfrei auf rechnung venta viagra generica generika tadalafil cialis kaufen in deutschland comprar viagra preis viagra kaufen comprar viagra original viagra legal kaufen venta sildenafil cialis farmacias del ahorro viagra preis in apotheke viagra schweiz rezept levitra ohne rezept potenzmittel cialis generika viagra niederlande sildenafil 50 mg precios medikament viagra viagra sicher bestellen levitra rezeptpflichtig viagra preis viagra similares viagra kaufen paypal cialis farmacias viagra in der apotheke costo sildenafil pillen viagra foro cialis viagra viagra rezeptfrei seriös cialis generico en peru viagra bestellen per nachname internet apotheke cialis similares viagra natural barcelona viagra kaufen auf rechnung viagra bestellen auf rechnung eu viagra günstig viagra viagra barata viagra online bestellen cialis berlin versandapotheke viagra generico sildenafil viagra pille preis generika tadalafil cialis cialis holland pastilla levitra cialis tadalafil bestellen kamagra kautabletten forum viagra generika wirkung comprar viagra masticable sildenafil comprar viagra sicher kaufen cialis kaufen billig preis viagra sildenafil viagra per nachnahme bestellen kauf viagra erektionsstorungen viagra farmacia similares viagra kaufen per nachnahme comprar viagra por correo sildenafil se vende sin receta viagra billig kaufen sildenafil mujeres viagra apotheke preis viagra 50mg preis cialis preise viagra billigst levitra versand viagra billig bestellen sildenafil marcas comerciales levitra receta kamagra niederlande precio de levitra cialis lilly preis generic tadalafil generika marcas viagra cialis sicher kaufen pfizer viagra preis kamagra rezept cialis online rezeptfrei sildenafil precio colombia super kamagra apotheke kamagra in apotheke viagra rezeptfrei in deutschland precio cialis en andorra ventajas cialis cialis 5mg filmtabletten viagra versandapotheke sildenafil magnus 50 mg original viagra cialis 12 preis viagra verkaufen vendo viagra en madrid sildenafil citrate kaufen billig cialis viagra generika 100 mg kamagra oral jelly billig viagra donde comprar viagra deutschland rezeptfrei viagra online bestellen rezeptfrei viagra generika unterschied cialis compra günstig kamagra viagra ohne rezept kaufen viagra ohne rezept erfahrungen viagra kaufen viagra kaufen seriös viagra generika vergleich kamagra pille cialis preisvergleich alternativen viagra comprar levitra original sildenafil necesita receta sildenafil para la mujer levitra venta libre similares levitra cialis 20mg filmtabletten preisvergleich cialis generico en andorra kamagra ohne rezept viagra kosten in der apotheke viagra precio en españa viagra kaufen ohne rezept viagra marcas comerciales original levitra rezeptfrei viagra preise in deutschland viagra preise frankreich vendo viagra santiago comprar cialis en sevilla comprar viagra paypal viagra medicamento comprar cialis contrareembolso viagra online bestellen forum cialis eds apotheke precios viagra cialis levitra cialis 5mg kaufen cialis generika forum kamagra kautabletten test viagra per nachname bestellen sildenafil argentina viagra apothekenpreise viagra generika nebenwirkung super kamagra billig kaufen erektion viagra generika shop viagra rezeptfrei ch venta levitra original viagra kaufen viagra rezeptfrei erfahrungen sildenafil frauen comprar viagra online españa kamagra precio viagra online bestellen erfahrungen viagra online kaufen ohne rezept levitra foro viagra verkauf kamagra preise comprar cialis farmacia tabletas cialis comprar cialis kamagra günstig levitra contrareembolso potenzpillen cialis kaufen schweiz comprar cialis andorra comprar viagra en internet potenz steigern viagra farmacias similares viagra por internet cialis mit rezept cialis original viagra generika ohne rezept cialis generika eu cialis kaufen forum viagra thailand kaufen sildenafil venta viagra apotheke rezeptfrei sildenafil billig comprar viagra sin receta barcelona cialis generika schweiz viagra apothekenpreis viagra andorra sin receta kaufen viagra comprar viagra feminino ersatz viagra kamagra pillen viagra alternativ original viagra ohne rezept billig viagra bestellen viagra holland ohne rezept medikamente rezeptfrei generika sildenafil cialis online apotheke cialis versand aus deutschland levitra receta medica viagra magnus viagra generika günstig foros viagra generico comprar viagra sin receta en barcelona sildenafil precio levitra bayer precio viagra kaufen test pillendienst viagra kamagra rezeptfrei sildenafil en mujeres kamagra eu kamagra in der apotheke rezeptfrei viagra kaufen levitra preis cialis holland rezeptfrei viagra online ohne rezept compra cialis online viagra preis türkei cialis auf rezept cialis 5 mg rezeptfrei kamagra soft tabletten kamagra oral jelly bestellen viagra generica levitra online bestellen sildenafil peru viagra ohne rezept holland viagra rezeptfrei viagra kaufen schweiz venta cialis online comprar viagra por telefono rezeptfrei viagra bestellen viagra oferta schweiz viagra sildenafil donde comprar viagra 50 comprar cialis españa cialis farmacia ahumada viagra billig online preisvergleich cialis 20 mg cialis media pastilla viagra rezeptfrei in spanien cialis medicamento günstig kamagra bestellen comprar cialis barcelona sildenafil preise preis viagra 100mg kamagra nachnahme kamagra contrareembolso viagra mit online rezept viagra natural foro viagra madrid viagra im ausland kaufen viagra ohne rezept sildenafil efectos a largo plazo cialis comprar madrid comprar viagra fiable viagra kaufen rezeptfrei viagra original kaufen viagra rezeptfrei erfahrungsberichte cialis rezeptfrei holland levitra kosten sildenafil de venta libre viagra farmacia andorra viagra sevilla kamagra kaufen berlin comprar viagra en andorra viagra generika preisvergleich tabletas sildenafil viagra im internet bestellen strafbar kamagra apotheke tadalafil rezeptfrei cialis preiswert kaufen rezept cialis cialis generika ohne rezept cialis 20mg filmtabletten preis sildenafil generico mexico foros viagra sildenafil 100mg magnus sildenafil cialis aus holland cialis generico en farmacias precios viagra apotheke kamagra niederlande viagra naturliche potenzmittel kamagra tabletten comprar cialis por internet cuanto cuesta el viagra viagra generica en españa comprar viagra seguro kamagra schweiz cialis generika erfahrung comprar cialis en madrid viagra comprar online viagra holland kamagra oral jelly günstig tadalafil 20mg preis precio viagra argentina viagra kostenlos cialis in deutschland kaufen viagra deutschland kamagra en venezuela venta de levitra vendo cialis barcelona kamagra kaufen forum comprar viagra andorra cialis generika preisvergleich kosten viagra rezept levitra online kamagra wien levitra precio viagra rezeptpflichtig sildenafil tabletten viagra nombre generico viagra nombre precio levitra 20 mg kamagra barato cialis generico foro viagra rezeptfrei günstig cialis rezeptfrei land comprar viagra en madrid rezeptfrei cialis viagra kostengünstig comprar cialis 20 mg holland apotheke viagra cialis kaufen deutschland vendo viagras viagra rezeptfrei preis cialis comprimidos viagra o similar viagra pille precio viagra españa comprar sildenafil contrareembolso sildenafil foro viagra kaufen günstig comprar levitra en andorra medicamento levitra cialis generika test kamagra sabores viagra kaufen in der schweiz viagra seriös bestellen viagra im internet bestellen viagra kosten mit rezept viagra generika 50mg filmtabletten cialis sildenafil pfizer levitra tschechien viagra 50 mg kaufen viagra generika aus deutschland cialis generika 20mg foro viagra natural cialis online kaufen firmel levitra viagra original oder generika

Bulletproof Mobile Device Detection and Style Sheets without User Agent Detection or Server-Side Scripting

by Dean Hamack

January 23rd, 2009

With the release of the iPhone and T-Mobile G1, smartphone sales have skyrocketed. Recent statistics show that at least one in one-hundred people accessing the internet is doing so via a mobile device. Developers have wisely taken note of this, and started optimizing websites for these devices. But even when you combine the iPhone and the G1 usage numbers, it still only accounts for about 50% of the mobile traffic in the U.S., and 35% in the rest of the World. That leaves a lot of other mobile users out in the cold.

Recently A List Apart published an article called “Return of the Mobile Style Sheet” by Dominique Hazael-Massieux. The aim of the article is to give developers a method to target not only the latest generation phones like the iPhone and G1, but other phones as well. While the article provides some good information, it has several major flaws:

  1. The data the author uses to determine device capabability is derived primarily from Mobile Test Harness (a site developed and maintained by the author). The statistics on this site are obtained through self-reporting by users, and the numbers are wildly inconsistent. Some users report passes, while others report failures for the same test. Others show passes for tests that failed when I conducted them on the actual device. I suspect part of this may have to do with people using mobile browser emulators (like iPhoney), rather than actual mobile devices. The rest of the disparity likely comes from users who have altered the default settings on their devices.
  2. The author misquotes his own statistics in the article. For example, he states that the BlackBerry browser supports only handheld style sheets. But both his own user generated statistics and my tests show that BlackBerries ignore the handheld media type.
  3. The method requires the use of four style sheets: a “core” stylesheet, a “screen” stylesheet, an “anti-screen” stylesheet, and a “handheld” stylesheet. All browsers regardless of the platform (handheld or desktop), have to load at least two out of four of these style sheets, and some load all four. That’s a lot of HTTP requests, especially for a device operating over a cellular connection.
  4. The method still requires the use of JavaScript or server-side scripting to catch the remaining devices not detected previously.
  5. The method fails on BlackBerries, Internet Explorer Mobile, and Symbian, which accounts for over one-third of the mobile devices in U.S.

After testing this method extensively, I decided to try and build a better mousetrap.

The result:

  • A method that works on approximately 85% of mobile devices
  • A method that requires only two style sheets, and issues only one HTTP request on most mobile devices

Do I have your attention? Read on…

“You can’t please all of the people, all of the time” (but you can give it a shot)

The first thing we need to do is determine who our audience is. The most accurate statistics I’ve seen on mobile device usage come from a company called AdMob:

“AdMob serves ads for more than 6,000 mobile web sites and 400 applications around the world. AdMob stores and analyzes the data from every ad request, impression, and click and uses this to optimize ad matching in the network.”

AdMob compiles both national and international usage statistics. Since I’m assuming most people reading this article are operating inside the U.S., we will focus on those stats for now.

AdMob Stats

iPhone and Android: 50% (combined)

Both the iPhone and Android support screen stylesheets, rather than handheld stylesheets. Fortunately, they also support CSS media queries, so targeting these devices is easy:

<link rel=”stylesheet” href=”handheld.css” media=”only screen and (max-device width:480px)” />

That covers 50% your audience.

RIM: 19%

Without a doubt, BlackBerries are the hardest to target. The problem is two-fold:

  1. Everytime RIM comes out with a new model, they change the way the browser operates.
  2. All of the various carriers (T-Mobile, AT&T, etc.) setup the devices differently.

I could only test a handful of the different models, but to my knowledge, no BlackBerry supports handheld stylesheets by default, and some don’t support them at all. JavaScript is supported on all BlackBerries, but it’s turned off by default. I conducted an informal survey of several B.B. users I know (including a guy who used to do tech support for AT&T), and not one of them was aware of this fact. That’s something to consider if your site is heavy on JS.

Other models (like the the 8900 Curve and the 8100 Pearl), take it one step further by turning off ALL stylesheet support by default. The user actually has to go into the browser settings and enable it. Once they’ve done that, they have the option to select either “handheld” or “screen” media types (handheld is the default). The screenshot below shows the Browser Configuration settings on a Curve.

BlackBerry Curve Browser Settings

While I applaud RIM for giving consumers that kind of flexibility, I wish they would take a cue from other companies and either (a) start supporting media queries, or (b) turn on handheld stylesheet support by default. I’m willing to bet they get a lot of support calls from people asking, “why do websites look like crap on my Curve?” I got just such a call from a client of mine, which is how I discovered this unfortunate fact in the first place.

The only BlackBerry that completely failed the test was the 8130 Pearl from Verizon. No matter what I tried, it always picked up the screen stylesheet, and there is no browser setting to over-ride it. The other BlackBerries I tested are generally a little easier to deal with. Unlike the ALA method, the one presented here works on both the Storm and the Bold 9000 (two of RIM’s most popular models), without changing any of the default browser settings. The other Pearl models are hit and miss depending on the carrier and the model.

The bottom line is that it’s a crapshoot when it comes to RIM, and there’s nothing you can do about it. Not even user-agent detection works 100% of the time on BlackBerries. No matter what method you use, you won’t be able to cover them all. Half the time your users will get your mobile stylesheet. The other half of the time they’ll get either the screen styles, or no styles at all. That’s why it’s so important to use good coding practices and avoid “grid” or table based layouts.

To be conservative, we’ll say this method works for roughly half the BlackBerry browsing population. So that’s another 10% of the mobile population covered.

Windows Mobile: 15%

With all the attention being paid to the iPhone and the G1 these days, Windows Mobile phones aren’t getting much press (or that much love from developers). But the truth of the matter is that Microsoft sold more phones than Apple did in the last quarter of 2008. So don’t count them out of the running just yet.

In their infinite wisdom, Microsoft decided to support both handheld AND screen stylesheets on Internet Explorer Mobile. So whatever is last in the cascade order wins. The good news is that all you have to do is place the handheld stylesheet after your screen stylesheet, cancel out any non-mobile friendly attributes, and you’re good to go. The bad news is, the browser has to load both, and depending on how big your stylesheets are, that could make for a pretty slow user experience. Fortunately, there’s a way we can prevent this. More on that when we get to the code.

Some savvy Windows Mobile owners use alternate browsers such as Opera Mini, or the promising new Iris browser, both of which support the “max-device-width” query. But like owners of PC desktops, the overwhelming majority seem to stick with IE. Once again, the method presented here succeeds, while the ALA method fails. Chalk up another 15%.

Palm OS: 9%

The popular Palm Treo and Centro use the Blazer browser built by NetFront. NetFront also offers a browser for Windows Mobile users. Like Mobile IE, NetFront supports both handheld and screen stylesheets, and doesn’t support media queries. Fret not, we have ways of dealing with NetFront as well… Add another 9% to our tally.

Hiptop: 4%:

If you’re over the age of 25, right about now, you’re probably thinking, “What the hell is Hiptop? Did P-Diddy start making a cell phone?”

Hiptop is the operating system used in T-Mobile Sidekick, which is popular with teens and tweens. The Sidekick is built by Danger, which was acquired by Microsoft last year. MS has big plans for the Sidekick (I know because they contacted me about becoming a developer ). So don’t expect Hiptop, or the Sidekick to go away anytime soon. Hiptop uses the AvantGo 3.2 browser, which also supports both handheld and screen stylesheets, and no media queries. I couldn’t get my hands on an actual Sidekick for testing, and their emulator is time consuming to set up. 

Symbian: 2%

Symbian is the OS used on Nokia phones. In the U.S., Nokia currently holds a pretty small market share, as a lot of their customers have switched teams. But in the rest of the world, Nokia is still king. Much to the dismay of a lot of Nokia owners, Symbian doesn’t support either the screen or handheld media type. It only supports stylesheets without a media declaration. So in order to target these users, we have to go old-school. There’s our final 2%.

Alright, alright. Gimme the code already!

Here you go:

<!-- Mobile device detection by Bushido Designs: BushidoDesigns.net -->
<link rel="stylesheet" type="text/css" href="mobile.css"  />
<style type="text/css" media="screen and (min-width: 481px)">
<!--
@import url("screen.css");
-->
</style>
<!--[if IE]><link rel="stylesheet" type="text/css" href="screen.css"  media="screen" /><![endif]-->
<link href="mobile.css" rel="stylesheet" type="text/css" media="handheld, only screen and (max-device-width: 480px)" />

Wait, that’s it?

Yep. Looks really simple, doesn’t it? But as the say, the devil is in the details.

Here’s the Breakdown:

  1. Line two:

    <link rel="stylesheet" type="text/css" href="mobile.css"  />

    Since some devices (like Symbian) don’t support stylesheets with a media declaration, we first need to include our mobile stylesheet for all users, regardless of platform. The only drawback to doing this is that desktop browsers pick it up as well. But mobile stylesheets tend to be pretty light, and it’s a lot easier to cancel out mobile styles in your screen stylesheet, than it is to do it the other way around (like the ALA method).

  2. Lines three through six:

    <style type="text/css" media="screen and (min-width: 481px)">
    
    <!--
    
    @import url("screen.css");
    
    -->
    
    </style>

    This is the key part of this method. Not all mobile devices support the “max-device-width” media query. But Firefox and Desktop Safari both support the “min-width” query. By using it, we can ensure that only those browsers pickup our screen stylesheet. Most mobile devices don’t understand “min-width” (like IE Mobile), “@import” (like Symbian), or both. And those that do, are smart enough to figure out that they shouldn’t import that stylesheet because their resolution is too low.

  3. Line seven:

    <!--[if IE]><link rel="stylesheet" type="text/css" href="screen.css"  media="screen" /><![endif]-->

    IE 6 and 7 don’t support the “min-width” query, so we need to use a conditional comment to make sure Desktop IE picks it up.

  4. Line eight:

    <link href="mobile.css" rel="stylesheet" type="text/css" media="handheld, only screen and (max-device-width: 480px)" />

    This is our safety net to make sure that any device that slipped through the cracks and somehow managed to pickup our screen stylesheet is going to get a second dose of handheld styles to over-write them.

Optional “Advanced Device” Stylesheet

As an option, you can include a third stylesheet for browsers that understand the “max-device-width” query. In most cases, I think this is unecessary, but you may want to do it if you are specifically targeting iPhone and Android users. If you want to do that, you just need to create an “amobile.css” stylesheet, and break line eight into two lines, like so:

<link href="mobile.css" rel="stylesheet" type="text/css" media="handheld" />

<link href="amobile.css" rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" />

Test Data

Mobile devices tested with this method:

  • iPhone/iPod Touch (Mobile Safari)
  • T-Mobile G1 (Android)
  • T-Mobile MDA (Windows Mobile 5: IE)
  • HTC S730 (Windows Mobile 6: IE, Opera Mini 4, and Iris)
  • LG Chocolate (Openwave 6)
  • Blackberry Storm, Blackberry Pearl (multiple models), Blackberry Bold, Blackberry Curve (multiple models)
  • Nokia Mobile Browser Simulator 4 (Symbian)
  • Treo 650 Simulator (Blazer 4)
  • Openwave V7 Simulator

Desktop browsers tested with this method:

  • Firefox 2 and 3
  • Safari 2 and 3
  • IE 6 and 7

Help contribute to this article by testing your device:

Want to help your fellow developers out by contributing to this article? Here’s how you can do so:

Go to the following url on your mobile device. In order to get accurate data, we request you use an actual device with the factory default settings, and not an emulator:

http://www.bushidodesigns.net/mt/

The test is very simple; if you are on a mobile device you should see a red background and the phrase “You are on a mobile device”. If instead you see a blue blackground and the phrase “You are on a desktop browser”, the test has failed. Either way, we want to hear your results.

Specifically, we’d like to hear from owners of the following devices:

  • Sony PSP (Playstation Portable)
  • Newer Nokia phones (N96 - N79, N810, etc.)

Happy mobile browsing.

Update - 01/31/09:

Ron Theis of Ridiculous Software was gracious enough to provide me with a Sidekick for testing. Unfortunately, it rendered the screen stylesheets. I also managed to get my hands on an LG Dare (LG’s iPhone clone), and the result was the same.  Stay tuned for further enhancements to the method.

Update - 02/18/09:

A reader wrote in and informed us that this method fails on the NetFront Browser (used on devices such as the Samsung Eternity). Further testing on this device reveals that it is pretty much impossible to serve an alternate stylesheet to NetFront users. In my humble opinion, companies like NetFront are shooting themselves in the foot by not adding support for handheld media types or media queries.

26 Responses to “Bulletproof Mobile Device Detection and Style Sheets without User Agent Detection or Server-Side Scripting”

  1. Visiting http://www.bushidodesigns.net/mt/ on a Chrome browser on a desktop PC returns the result "You are on a mobile browser" on a red background.

    Posted by: connectme360 on February 17th, 2009 at 11:15 pm

  2. Thanks for the comment. I just checked it on Chrome and it worked fine for me. I posted a screenshot here: http://www.bushidodesigns.net/blog/img/content/chrome.png

    Posted by: dean on February 18th, 2009 at 10:29 am

  3. The test works correctly in my Nokia 6500 Slide phone — user agent string: Nokia6500s-1/2.0 (04.81) Profile/MIDP-2.1 Configuration/CLDC-1.1

    Note that the 6500 Slide and the 6500 Classic, despite the common 6500 designations, are completely different phones and have different browsers. From my own experiments, with screen and handheld stylesheets available, the 6500s will render the handheld styles and ignore the screen styles, while the 6500c will attempt to render both the handheld AND the screen styles.

    Posted by: Keith Bell on February 26th, 2009 at 7:18 pm

  4. Blackberry 8330 Curve on Verizon:

    >Default settings yields this result:

    "You are on a desktop browser"
    "You are on a mobile device"
    "You do not have javascript"
    all on a white background

    >Turning on support for scripts yields blue background and "desktop browser" message

    There doesn't seem to be any way to change to change style sheet smedia type on the older Curve model, but there is a newer phone OS out there… takes an hour or more to update but I might try it just for this.

    Posted by: matthammond on March 1st, 2009 at 8:38 pm

  5. Using Opera Mini same device test works properly

    Posted by: matthammond on March 1st, 2009 at 8:45 pm

  6. Hi,

    I'm the author of the article in A List Apart; thanks a lot for contributing what looks like a promising alternative technique!

    I have been experimenting with it a bit, and from what I've been told (I haven't been able to check first hand), it looks like it doesn't work with Nokia S60, unfortunately.

    That said, to facilitate collecting data on that technique, I've taken the liberty to create a corresponding test case in the test suite where I had been experimenting it:
    http://www.w3.org/2007/11/cssmedia-mobile/
    and integrating it in the test harness that allows to collect data on the results:
    http://w3.org/brief/MTEy

    (the results are collected as part of the results on the other tests, but I can try and extract them at some point in the future if there is sufficient interest).

    HTH,

    Dom

    Posted by: dom on March 6th, 2009 at 7:48 am

  7. I've tried your technique on http://smidig2009.no but can't get the page to validate because of it:

    http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fsmidig2009.no&profile=none&usermedium=all&warning=1&lang=en

    This seems to be a long-standing (since 2004, at least) bug in the CSS validator, because the code is valid according to the CSS spec:

    http://www.456bereastreet.com/archive/200701/the_w3c_css_validator_fuji_release/

    The bug only shows up when the base document is fed to the validator. When the validator is fed the stylesheets themselves, it doesn't complain. This is frustrating because standards are important to our organization, so we like to advertise the fact that our pages validate by linking to the validator results.

    I am happy to report, however, that your method works on my friend's G1, plus the native browser in the versions of S60 on my husband's E71.

    Posted by: sjbrodwall on March 18th, 2009 at 9:46 am

  8. sjbrodwall: If you use the W3C validator, the HTML validates just fine:

    http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fbushidodesigns.net%2Fmt%2F

    The css chokes, because the "min-width" and "max-device-width" media queries are part of the CSS 3 spec, and the validator uses CSS 2.1 specs.

    Posted by: dean on March 18th, 2009 at 10:12 am

  9. I haven't had any problem with the HTML validator, just the CSS validator. The CSS validator lets you validate against the CSS3 spec under "More Options", but I still get the same error:

    http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fsmidig2009.no%2F&profile=css3&usermedium=all&warning=1&lang=en or http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fbushidodesigns.net%2Fmt%2F&profile=css3&usermedium=all&warning=1&lang=en

    I also meant to include that the technique works on my N85 in addition to the E71. The E71 has S60 Feature Pack 1, whereas the N85 has Feature Pack 2, which might be important because there have been some changes to the native browser.

    Posted by: sjbrodwall on March 19th, 2009 at 7:04 am

  10. I hate to say it, if you're going to get into the mobile game, you're going to have to forget about valid CSS. Many of the iPhone specific styles (such as "-webkit-text-size-adjust") won't validate, but they are essential to a good mobile experience. Personally, I've never been too concerned with my CSS validating, as long as my HTML does.

    Thanks for the info on the Nokias. Rumor has it they are going to start building their phones on the Android platform. If so, it will bring us one step closer to mobile consistency.

    Posted by: dean on March 19th, 2009 at 1:22 pm

  11. So depressing! About having to forgo valid CSS, I mean–the bit about Nokia and Android would be a dream come true.

    Posted by: sjbrodwall on March 22nd, 2009 at 8:35 am

  12. Tested on a iPhone, iTouch and Nokia N82 and it worked fine for me.

    Posted by: msp on March 24th, 2009 at 9:13 am

  13. Thanks for doing all this work, Dean - immensely useful (and you get a top-notch Google rank to boot!). I've also confirmed that the Blackberry 8320 (via T-Mobile) has stylesheets turned off by default, even for the "handheld" media type - truly mystifying why they would build something and then disable it.

    Posted by: davigoli on March 27th, 2009 at 1:01 pm

  14. Motorola RAZR 3A Openwave 6.2.3

    Red field with text:
    You are on a mobile
    device
    You do not have
    javascript

    This is not my target devices for studying this article, but it is the device I use (for now).

    Posted by: rdblaha1 on April 6th, 2009 at 12:32 pm

  15. Thanks for reporting. The Razr is the second highest selling phone of all time (next to the iPhone), so there are a lot of them out there. Good to know this works on them.

    Posted by: dean on April 6th, 2009 at 2:32 pm

  16. Nintendo DSi with Opera
    UserAgent : Opera/9.50 (Nintento DSi; Opera/483; U; fr)

    You are on a desktop browser
    You have javascript

    Posted by: Akasam on April 16th, 2009 at 1:45 pm

  17. I copied the code above but some of the css from the mobile.css (from line two above) is trumping my screen.css file and breaking my site. The trumping isn't consistent eg. Some background images are getting turned off and others aren't. I can't see any rhyme or reason as to why some rules would have a higher priority and others don't. If i inspect it in firebug I can see that the mobile rules are sometimes at the top of the cascade and other times not. If anyone has any ideas why that would be happening that would be great?

    Posted by: kobuk on April 21st, 2009 at 1:26 pm

  18. kobuk: I put this method into effect on a fairly involved site I'm working on right now and had some similar problems when it came to rendering on the iphone.

    I'm going to let you in on a secret though… sometime in the next couple of days I'm going to be publishing a new article about how everything we've all read about the percentage of people with js disabled is completely and totally false. The Cliff Notes version is that you can throw this method out the window and use this instead:

    <head>
    <link rel="stylesheet" href="mobile.css" type="text/css" />
    <script language="javascript" type="text/javascript">
    if(screen.width >= 461) {
    document.write('<link rel="stylesheet" type="text/css" href="screen.css" media="Screen" />');
    }
    </script>
    </head>

    Check back soon to get the full scoop.

    Posted by: dean on April 21st, 2009 at 11:19 pm

  19. I don't if is a good post for this article.
    I have published the new version of Apache Mobile Filter, now the filter is give to you the information of capabilities as apache environment.
    Now you can develope in any language (php,jsp, ruby etc.) and have the information of mobile capability.

    Read more info here: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html

    Posted by: ifuschini on May 27th, 2009 at 3:54 am

  20. Nokia N810 Internet Tablet
    Default browser called microb, firefox-based.

    Detected as:
    You are on a desktop browser
    You have javascript

    Posted by: hgtablet on June 12th, 2009 at 6:02 am

  21. hgtablet: that's because the screen resolution of the N810 is larger than 480 pixels (800 x 400 to be exact). If you want to serve mobile stylesheets to that device, you would need to change the "min-width" number to 801. Personally, I don't consider a device with that high of resolution to be a mobile device, so I'll stick with what I have.

    Posted by: dean on June 16th, 2009 at 10:48 pm

  22. Here are some "Sony PSP" and "SonyEricsson K530i" results

    Sony PSP with Access Netfront 3? (definitely Netfront)
    PSP resolution is 480×272 but…
    on blue: You are on a desktop browser
    JS on: You have javascript
    JS off: You do not have javascript

    and

    SonyEricssonK530i NetFront 3.3
    on red: You are on a mobile device
    JS on: You have javascript

    please also have a look at the test results on
    http://www.w3.org/2007/03/mth/results?ts=cssmedia
    SonyEricssonK530i/R6BC Browser/NetFront/3.3
    Profile/MIDP-2.0 Configuration/CLDC-1.1
    100% tests run)
    Test results are in column no. 22 (now).

    Screenshots (photos) @ http://marcup.de/mobile/bushido/

    Posted by: MobileMarc on July 9th, 2009 at 4:08 am

  23. Using a Samsung Rant on Sprint,
    MyUserAgent is: Samsung-SPHM540 Polaris/6.0 MMP/2.0 Profile/MIDP-2.0 Configuration/CLDC-1.1
    Browser, per phone software, is Polaris/6.0

    Visiting the mobile-test page gives me: "
    You are on a mobile device

    You have Javascript"
    as black text on a white background. I did notice in the location that Sprint was intercepting the request, if that potentiall makes any difference.

    Posted by: westleyd on July 12th, 2009 at 11:01 am

  24. From what you say:

    "But mobile stylesheets tend to be pretty light, and it’s a lot easier to cancel out mobile styles in your screen stylesheet, than it is to do it the other way around (like the ALA method). "

    it seems there is no need to cancel out screen styles in the mobile styles: but that is not true.
    If a mobile phone doesn't understand css media queries and picks up style sheets for both screen and handheld media type (like my Nokia 2630), then you need a sort of "antiscreen.css" embedded or imported (like the ALA method).
    Your test is fine for my phone because it picks up the stylesheets in the following order: mobile.css, screen.css and finally mobile.css again, but in real cases there will be mobile-unfriendly settings in screen.css that must be canceled out in some way.

    Posted by: Andrea on July 20th, 2009 at 9:23 am

  25. I just tried it on a Nokia N97 and it works as expected:

    You are on a mobile device
    You have javascript

    All on a red background.

    Posted by: brunogirin on August 29th, 2009 at 5:06 pm

  26. A further note on the Nokia N97: going through the test cases posted by Dom at http://www.w3.org/2007/11/cssmedia-mobile/ is appears that the N97 fails tests 5, 6, 7, 8, 9 and 10 but passes all the others. In particular, it passes tests 11, 12 and 13 which means that it doesn't seem to accept media handheld but understands media queries.

    Posted by: brunogirin on August 30th, 2009 at 12:22 pm