Fault inside JQuery 1.9.1 in IE9
I have a web application which has jQuery loaded, but does some manipulation of DOM objects directly.
When upgrading to 1.9.1, this application causes jQuery to fault when run inside IE9 in Quirks mode.
At line 2627 of 1.9.1, the code involved is:
// href/src property should get the full normalized URL (#10299/#12915)
jQuery.each([ "href", "src" ], function( i, name ) {
jQuery.propHooks[ name ] = {
get: function (elem) {
return elem.getAttribute( name, 4 );
}
};
});
The "getAttribute" call fails. When it fails, "elem" contains the current document URL object, and "name" contains the value "href". The error given is: Object doesn't support property or method 'getAttribute'
The properties the elem object DOES support are:
constructor
hash
host
hostname
href
pathname
port
protocol
search
and the methods are:
assign
reload
replace
toString
Now this is beyond me, I don't pretend to know the internals of jQuery. I do know that it's doing something different here in 1.9.1 that was working fine in previous versions. I have no idea what is calling the function - it is an ASP.Net (4.5) application, and the function that causes the fault is a standard .Net button handler function - but to my knowledge, there is no jQuery code within the handler itself.
In any case, wrapping a try/catch around the function as shown below eliminates the error, and the application functions correctly. I have no idea what the problem is, I hope I've supplied enough info that someone can identify what is going on and make a suggestion.
// href/src property should get the full normalized URL (#10299/#12915)
jQuery.each([ "href", "src" ], function( i, name ) {
jQuery.propHooks[ name ] = {
get: function (elem) {
var result = null;
try {
result = elem.getAttribute( name, 2 );
}
catch(err){}
return result;
}
};
});