News for hackers. Stuff that matters.
Re:IE6IFY by nbpoole on Wednesday March 16, 2011 @05:34PM (#2334050)
Not quite. Here's the cleaned up JS from the bookmarklet:

    function () {
    var i = 0,
        r = function (n) {
            return Math.floor(Math.random() * n)
        },
        f = document.getElementsByTagName('body')[0].getElementsByTagName('*'),
        o = function (e) {
            return typeof(e.style) == 'object' && e.tagName != 'SCRIPT'
        },
        s = function () {
            while (!o(e = f[r(f.length)])) {}
            return e.style
        };
    while (i++ < 5) {
        s().display = r(2) ? 'block' : 'inline';
        s().position = r(2) ? 'absolute' : 'relative';
        s().margin = r(2) ? '0' : '1em';
        s().padding = r(2) ? '0' : '1em';
        s().width = r(2) ? '' : 'auto';
    }
    })();
Every time you click the button, it does the following:

1. Randomly selects an element from the page that isn't an object or a script.

2. Randomly switches the display property to either block or inline, the position property to absolute or relative, the margin property to 0 or 1 em, the padding property to 0 or 1em, and the width to a blank string or auto.

3. Repeats steps 1/2 until 5 elements have had these transformations applied.

Re:IE6IFY by armandososa on Wednesday March 16, 2011 @06:01PM (#2334158)
why use

    document.getElementsByTagName('body')[0]
instead of

    document.body
?

(it's a legit, not snarky, question )

EDIT: formating.

Re:IE6IFY by nbpoole on Wednesday March 16, 2011 @06:19PM (#2334218)
Because maybe there's more than one body? :P

[Seriously though, I have no idea]

Re:IE6IFY by generalk on Wednesday March 16, 2011 @10:25PM (#2334841)
You know, you're probably fine if you always assume there's only one body tag.

That said, I've seen this and worse when looking at the output of highly-paid web dev departments at large companies. One site we recently saw had five opening html tags, head sections, and body tags. All the head sections were different, and none were closed, including roughly half the content tags we saw. It's a testament to the "be loose in what you accept" mantra of the web, and to the browser devs themselves, that this monstrosity rendered properly.

I'm not saying "enterprise" developers are bad by definition, but the enterprise sure is large enough for the bad ones to sneak by.

Re:IE6IFY by long on Wednesday March 16, 2011 @07:59PM (#2334512)
getElementsByTagName always returns a NodeList, which is an Array-like object. You want the first thing in the array.
Re:IE6IFY by bauchidgw on Wednesday March 16, 2011 @07:59PM (#2334507)
there is nothing i havent seen before.... a multi million euro betting site (sponsor of real madrid) had this for years until i suggested it was a bad idea (and a lots of dev man days later......)
Re:IE6IFY by long on Wednesday March 16, 2011 @08:00PM (#2334517)
Props for typing up a more detailed version, which is what I started to do, but then got lazy and decided to make a somewhat vague general statement.