hasAttribute
method of dom elements. Which isn't that bad since its fairly trivial to replace hasAttribute
with getAttribute
. The scary thing is that this issue has been present since November 2007.Apparently (looking through the history) there was an attempt to fix back in January of 2008, by changing
hasAttribute('missing')
to getAttribute('missing', 2) == ""
. (I'm not sure where the 2 came from. All the docs i've read seem to state that getAttribute
only takes 1 parameter) This almost would have worked, except for one important fact. In the mediawiki api, if you try to find info on a non-exisistant page, it will give you: <page
... missing="" />
[1] Thus the normal value for the attribute if present is "", and if its not present, according to the w3c getArribute
should return the empty string. Thus testing for the empty string doesn't work, as it returns the empty string in both cases. However in practice this doesn't seem entirely true, as in both Firefox and IE, when getAttribute
is used on a missing attribute, the browser returns null
instead of ""
(The previous code of getAttribute('missing', 2) == ""
would still of worked since "" == null
)To fix the problem, the code in question now first tries to use the
hasAttribute()
method (for the good little browsers that support it), and if that throws an exception, it will see if getAttribute(attributeName) !== null
. (assuming that anybody who doesn't support hasAttribute
also returns null when getting a non-existant attribute.Anyways, the moral of this story is that we should probably set up some system for tracking problems with the local javascript on wikinews, since this problem was discovered and than totally forgotten. perhaps on [[Wikinews:Javascript]].