Forum Moderators: open

Message Too Old, No Replies

node.hasAttribute and IE(Mac)

work-around?

         

dcrombie

9:12 am on Jun 28, 2004 (gmt 0)



IE(Mac) fails silently when it encounters this code:

if(node.hasAttribute(attr)) ...

Does anyone know a clean way (ie. not using browser detection) to have IE(Mac) skip this line?

W3C DOM Compatibility and test cases [quirksmode.org]

Bernard Marx

10:10 am on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<edit>
I was wondering about my post below. Especially whether getAttribute is good to use in IE mac. In the process, I found this link which seems to cover the problem of whether an attribute actually is present or not, in a X-browser view (incl. Mac).

[pxl8.com ]

..but then again, the 3 tests they do [==null,=="",==undefined]
since all [null,"",undefined] evaluate to false,
can be rolled into one - similar to below, but opposite.

if(!node.getAttribute(attr))

</edit>
Hmm. No browser detection. Do you mean directly? As in querying navigator string etc?
Or generally. A test for IE mac (once IE is established) could be a test for the constructor:

if(!ActiveXObject) [hmmm. what happens if it's disabled? Anyway, something similar]

Otherwise:

if(node.hasAttribute && node.hasAttribute(attr)) 

but if IE mac was failing silently before, then it's likely that it will pass the new first condition too.
(Another IE mac "phantom method").

Would it be possible to use getAttribute instead?
In all cases (since XHTML element attributes must have values)

if(node.getAttribute(attr))

will save the same purpose in your code.
...perhaps

dcrombie

1:37 pm on Jun 28, 2004 (gmt 0)



Thanks for the quick reply. I did some testing myself after posting the questions and came up with this which seems to work:

if(node.hasAttribute) { 
if(node.hasAttribute(attr)) return node.getAttribute(attr);
}

which is pretty much what you said ;)