ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

IE<8 'href' and 'src' special case #33

Closed rvagg closed 13 years ago

rvagg commented 13 years ago

Yet more special cases not picked up by existing tests that I've bumped in to this week. $(a).attr('href') won't return the exact href in IE pre 8, same with img src. If you have a relative path or a #hash then IE decides that you really want the absolute path instead. So use cases like this don't work: https://github.com/twitter/bootstrap/blob/master/js/bootstrap-scrollspy.js#L39

Thankfully, passing 2 as the iFlags argument to getAttribute in IE (see http://msdn.microsoft.com/en-us/library/ms536429%28v=vs.85%29.aspx) gives us what we want.

Feature test at the top, extra conditional in attr().

Passes in IE6+. Though there are still other tests failing in IE6,7,8 and a single style test still failing in IE9. I'll try and look into some of these when I get some time.

Same problem exists in qwery, in the attribute check; I'll try and submit a pull request for that when I have a chance.

rvagg commented 13 years ago

Rolled in to 34, closing: https://github.com/ded/bonzo/pull/34

mferraro commented 11 years ago

I've the same problem with $('#id').attr('class'), could be a similar error?

krmgns commented 11 years ago

Actually, there are many troubles about attributes on IE. Here is a list: http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html

I tried to map all those problems here: https://github.com/qeremy/mii/blob/master/mii.dom.js#L869

e.g:

var attrs = el.attributes, val;
switch (key) {
    case "class":
    case "className":
        val = attrs["class"] && attrs["class"].specified
            ? el.className : null;
    break;
mferraro commented 11 years ago

Tnx qeremy!

rvagg commented 11 years ago

If possible, @mferraro & @qeremy, a pull request with at least some test cases to demonstrate the problems would handy, code to fix would be even handier. To be honest, making stuff like this work for older versions of IE is becoming much less of a priority (certainly IE6 & IE7 are almost off the radar now and we're just waiting for IE8 to die a proper death), so unless others want to contribute to fixing these edge-cases, core contributors are unlikely to find the time to do so on their own.