Skip to main content

IE7 HREF Normalization and AJAX

Front-end Development

I have often relied on jQuery's awesome cross-browser compatibility tricks. One of these is fixing an inconsistency with how link HREFs are reported in IE compared to other browsers. In most browsers, when asking for the HREF of a link, JavaScript sees what is actually in the document source. In IE, however, the HREF attribute is "normalized" into a fully-qualified URL. This can be a problem. Generally, jQuery fixes this for you when you use the .attr() method to retrieve the "href" attribute. The returned value is whatever is in the source code, not the normalized URL, regardless of browser. Success! Unfortunately, I discovered today that is not always the case. In this specific scenario the normalization still happens:

  1. Open IE7.
  2. Use AJAX to load some content into the page that contains links.
  3. Examine the link HREF using .attr('href').
  4. See that the result is a normalized URL. Oops.

I haven't yet performed reductions to see if the problem is the AJAX load or the DOM insertion, but it only affects IE7, not IE8. At this point, my workaround is to do the regexes manually to extract the part of the HREF I want, rather than relying on jQuery. Clumsy, but it works!

Need a fresh perspective on a tough project?

Let’s talk about how RDG can help.

Contact Us