Skip to content
Permalink
Browse files
Fix #12945. Check for .getAttribute so IE9 is happy.
  • Loading branch information
dmethvin committed Jan 4, 2013
1 parent abead1c commit a95f35744aff95a446cc05e1d8c558b3a4867836
Showing 1 changed file with 5 additions and 1 deletion.
@@ -330,7 +330,11 @@ jQuery.extend({

} else {

ret = elem.getAttribute( name );
// In IE9+, Flash objects don't have .getAttribute (#12945)
// Support: IE9+
if ( typeof elem.getAttribute !== "undefined" ) {
ret = elem.getAttribute( name );
}

// Non-existent attributes return null, we normalize to undefined
return ret == null ?

3 comments on commit a95f357

@nuxodin
Copy link

@nuxodin nuxodin commented on a95f357 Jan 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply this?

if( elem.getAttribute ){
...
}

@dmethvin
Copy link
Member Author

@dmethvin dmethvin commented on a95f357 Jan 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flash objects aren't native JavaScript objects, they're host objects built off Microsoft COM. They did it wrong and don't understand the difference between a property reference and a function call. Checking for falsy via elem.getAttribute actually calls the method with no arguments. The typeof gets around that. This problem also happens with DOM objects in IE8 and lower.

@nuxodin
Copy link

@nuxodin nuxodin commented on a95f357 Jan 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, thank you

Please sign in to comment.