|
|
|
| Hurry! Enter The Daily WTF's OMGWTF2 Contest by June 28th! - Prizes! Fame! Trophies! Do your worst: http://omg2.thedailywtf.com/ |
| « I'm not Null, I'm a Human Being! | Too Much Sleep » |
Creating websites so that they display the same on all browsers and platforms for all vendors is tough business. Designers aim for "One size fits all" but sometimes, even with the best of incantations, "One size fits most" is the end result.
Case in point, Eric's simple goal: learn more about Asus' Transformer Book. All that he wanted to do was to pull up http://transformerbook.asus.com/ on his Ubuntu laptop and marvel at the dynamic animations and glitzy transitions between product features but instead all he got was a screenful of ugly. No text styling, a couple of images, but mostly just blah-looking plain text.
Considering this to be strange, he pulled up the same site on a friend's MacBook and on there, everything was normal.
Curious, he opened up the developer console in his browser and saw this:
Yep, that's right - since Eric's laptop isn't a Windows or Mac based machine, an iPad, iPhone, or Android device, the JavaScript just dies, leaving him stuck in a lurch.
...but the WTF's don't stop there.
Below is the full JavaScript source for your reading enjoyment (source). For fun, compare it to how it fits in with the rest of the site and wince as you learn the script's purpose.
// JavaScript Document (function(){ isIE = navigator.userAgent.search("MSIE") > -1; isIE7 = navigator.userAgent.search("MSIE 7") > -1; isIE10 = navigator.userAgent.search("MSIE 10") > -1; isFirefox = navigator.userAgent.search("Firefox") > -1; isOpera = navigator.userAgent.search("Opera") > -1; isSafari = navigator.userAgent.search("Safari") > -1;//Google瀏覽器是用這核心 if(isIE7){} if(isIE){} if(isFirefox){} if(isOpera){} if(isSafari){} if(isIE10){} if( navigator.platform.indexOf("Win") == 0 ) { webMode = "PC"; }//WIN if( navigator.platform.indexOf("Mac") == 0 ) { webMode = "PC"; }//MAC if( navigator.platform.indexOf("iPad") == 0 ) { webMode = "PAD"; }//IPAD if( navigator.platform.indexOf("iPhone") == 0 ) { webMode = "PHONE"; }//IPHONE if( navigator.platform.indexOf("iPod") == 0 ) { webMode = "PHONE"; }//IPOD if( navigator.userAgent.match(/Android/i) ) { webMode = "PHONE"; }//ANDROID /* if( webMode == "PHONE" ){ $('head').append('<meta name="apple-mobile-web-app-capable" content="yes" /><meta content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" name="viewport" /><link type="text/css" rel="stylesheet" href="css/index_phone.css" />'); }else if(webMode == "PAD"){ $('head').append('<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"><link type="text/css" rel="stylesheet" href="css/index.css" />'); }else{ $('head').append('<link type="text/css" rel="stylesheet" href="css/index.css" />'); } */ if(webMode == "PAD"){ $('head').append('<link type="text/css" rel="stylesheet" href="css/index.css" />'); }else{ $('head').append('<link type="text/css" rel="stylesheet" href="css/index.css" />'); } })();
|
Well, it is a Win8 gadget. They really intend to keep desktop Linux/BSD users from being their customers, as is apparent here.
|
Re: Website WTF - Asus Transformer Book
2013-01-21 09:30
•
by
RaceProUK
|
Almost. I'd go for the following: First rule of browser sniffing: Don't do it. Second rule of browser sniffing: Seriously, don't do it. Third rule of browser sniffing: If you do it, I will remove your reproductive organs slowly with a cheese grater. |
Re: Website WTF - Asus Transformer Book
2013-01-21 20:48
•
by
Amakudari
(unregistered)
|
|
WTFs:
1. Three methods of string matching: search (without regexes, no less!) greater than -1, indexOf equal to 0 and match 2. Browser sniffing. There is no discussion worth having here; a site with this little sophistication doesn't need it. 3. Why does it skip over MSIE 8-9? Shouldn't they at least be included with MSIE 7 instead of MSIE 6, featurewise? File under why browser sniffing is bad. 4. if(condition){} - Worse than commenting out code: leaving it there because it has no side effects. Stupid whether optimized away or not. 5. Oh, hey, apparently they know match exists and know at least something about regex; but they aren't even using /Win|Mac/ or /iP(hone|od)/ ? Not necessary, but hey, as long as we're going down the rabbit hole of browser sniffing... 6. No switch here? Really? There's no default. 7. And for that matter, you can even get by without a switch by just declaring your variables. var webMode; at the top of the function actually fixes the later comparison. 8. Oh, good, I was worried we wouldn't get to commented-out code. 9. if a then b else b - Genius when a can break 10. Tabs xor spaces for indentation You sense it's sincere, an earnest attempt to ape halfway-competent code, and there's a slightly endearing quality in its abject failure. Very slightly. Most impressive is that, due to the complete lack of consistency littering the code is that clearly several eyes have seen this code. |
| « I'm not Null, I'm a Human Being! | Too Much Sleep » |