Skip navigation.

exploreopera

| Help

Sign up | Help

Dell goes for the quirks

, , , ,

This page should have a Flash in it. Now Opera, where is it?

Well, here's a pretty little function from Dell, meant to return an element with a specific name:

function ParseDivObjects( targetName )
{
var objs = document.getElementsByName( targetName );

//-- Workaround for "inconsistent" W3C ruleset in IE as DIV's aren't mapped with name properties
if( objs.length == 0 )
{
var targets = document.getElementsByTagName( "DIV" );
var tmpObj;

objs = new Array();

for( var targetidx = 0; targetidx < targets.length; targetidx++ )
{
tmpObj = targets[targetidx];
if( tmpObj.name == targetName )
{
objs.push( tmpObj );
}
}
}
return objs;
}


Let's start: document.getElementsByName is not supposed to be used for elements that are not supposed to have a "name" attribute. So, for example you can use getElementsByName with INPUT elements but not with DIV. Except that Mozilla apparently disagrees with that interpretation of the specification and thinks IE's behaviour is "a quirk". Really?

Anyway, Dell has a workaround for IE: they go through all DIVs in the page and check tmpObj.name, which means Opera is out of luck again. Since DIVs are not meant to have a "name" attribute we don't create any .name property for it. Using getAttribute here would make it work.

So Dell crams two different quirks into one function, and Opera fails because it supports neither. Time to violate the DOM spec a little more.. :frown:

GMail's while(1) demystifiedTwo small steps for Gates towards a better web

Comments

avatar
Ehm... why don't they just use an ID :insane:

By Jere, # 22. May 2006, 14:24:32

avatar
@Jere: That was my first thought as well. This seems like a clear case of using a screwdriver as a hammer and trying to work around the fact that it doesn't pound nails very well.

By Kelson, # 22. May 2006, 17:11:31

avatar
I think they use "name" because the script is meant to support embedding several Flash thingies in one page.

By hallvors, # 22. May 2006, 18:01:14

avatar
I can see Mozilla's point of view...

By Andrew Gregory, # 23. May 2006, 01:46:08

avatar
I guess it will later boil down to another question of DTD parsing and how to determine the "name-ness" of an attribute, just like with ID - but hey, I think the spec is unclear and what Mozilla does is the behaviour a web developer who didn't read the fine print would expect so I'd like us to follow them..

By hallvors, # 24. May 2006, 23:54:30

avatar
:cheers:

By qicai02, # 7. June 2006, 09:30:28

Write a comment

You must be logged in to write a comment. if you're not a registered member, please sign up.