1. Lies, lies, and Android’s stock browser

    While working on a responsive site that featured some CSS 3D Transforms, I found that, for some reason, clicking into a text input to type on Android 2.3 and below caused the automatic scroll to the input to exhibit a strange yoyo behavior. It would jump down about 300px too far, jump up a bit, jump down again, up one more time, and park itself a couple of hundred pixels south of the actual input location.

    After a ton of messing around, I realized that it was related to another bug: the stock Android Browser’s incomplete support for CSS 3D Transforms and transitions.

    Despite Modernizr reporting that it’s supported, Android 2.3 and below will in fact fail to properly perform a rotateY transform, instead performing a regular rotate. Additionally, the very presence of an element with 3D transition properties seems to cause the jumpy behavior on input focus.

    Because feature detection yields a false positive, I had to actually detect the version of Android being run via the user agent string, and add a class to the body as needed, so I could target it separately and force the fallback animation I’d written to kick in on Gingerbread, FroYo, and below (to be safe, I also added Honeycomb, since I didn’t have an Android 3 tablet to see if it worked on it).

    var ua = navigator.userAgent.toLowerCase();
    var isOldAndroid = /android [1-3]/i.test( ua );
  2. A IE, you never cease to amaze and surprise me!

    A relatively little known, and even less appreciated, way of doing a for loop in javascript works as follows:

    for (key in array) {
         var element = array[key];

    You might recognize this as essentially the equivalent of the foreach loop in php and other languages. It’s a very useful structure when dealing with associative arrays, or just to save yourself some typing. Unfortunately, there are some quirks with this approach. Notably, as usual, in Internet Explorer.

    While at work today I was looping through some form elements, in case the page the script would ran on had multiple forms. Though my test page only had a single form element in it, IE gave me multiple additional elements, such as the letter p, and the number 13…

    Worse still, it did the same for the form.elements array within an inner loop. I did some investigation and found that this is a bug in IE, and has been around for a while now.

    So thank you IE8, for showing us yet again that as far as you’ve come, you’re still the bottom of the proverbial browser barrel.

    Also, thank you Doug for also writing a post on this issue… albeit over 3 years ago 😛 I just felt I should share the fact that this is still very much an issue which IE has, even in its most recent version.

  3. Fun Fact #372

    Remember, Javascript, like most languages, short-circuits when dealing with if statements.

    What does that mean?

    Well for example, when running an OR evaluation with two functions, such as

    if(doThis(var1) || doThat(var2)){

    If the first function is true, the second function will not execute.

    Something to keep in mind for future reference if you’re wondering why your function’s not running.

  4. The Impossible Octal

    Hehe, here’s a little trick I learned from TDWTF… Thought it’s really less of a trick, and more of an “I can’t believe it’s that broken” moment.

    In the title bar of your browser, add this:

    javascript: alert(parseInt('05'));

    You get 5, right?
    Now try this:

    javascript: alert(parseInt('09'));

    Yup, that’s right, you get a 0.

    Here’s the article with the explanation for this odd output:

    If you guessed 9, you fail. No, it’s zero. See, Javascript supports octal numbers. Any number starting with a zero is octal, even if it can’t be an actual octal number. In certain languages, like Perl, trying to use a non-octal number as an octal number results in an error. In other languages, like Javascript, it silently fails.

    So, thank you Javascript, for teaching me something I didn’t know about you… and making me hate your quirks all the more.