URL Components in the DOM

The IE team has been working our way through the remaining issues reported from internal and external testing of the IE9 Release Candidate. In the course of investigating one recent internal-site compatibility bug, I ran across an interesting interoperability issue that appears to have existed since IE5 (or earlier). It isn’t well-documented, even as it is periodically rediscovered, so I figured that it was worth a mention here.

The specific issue is that Internet Explorer’s accessor methods for URL components do not match the spec in some cases. Specifically, the host property sometimes includes the port number (even when that port is the default port for the scheme) and the pathname property sometimes lacks the leading forward slash character.

You can see these quirks on a simple test page: https://bayden.com/test/path.htm.

Screenshot of test page

When loading the page, the <A> element’s properties are incorrect, but the window.location object has the correct values. However, when the page is loaded into a dialog using the ShowModalDialog or ShowModelessDialog methods, the window.location object also has the non-standard values. Interestingly, you’ll also always see the non-standard window.location values when loading the page in Platform Preview Builds (direct hosting of MSHTML), but applications that host the Web Browser Control behave like the full browser.

This behavior only exists in Internet Explorer (and hosts of MSHTML), and it’s related to an internal boolean flag whose value is different in the affected cases.

This isn’t a regression in IE9, but it was noticed during our testing because of an unrelated change—IE9 RC throws an exception when setting the <base> element’s href to an invalid value. The site in question was using the DOM properties to construct a URL to assign to a BASE element’s href property, and that operation began throwing an exception in IE9. In IE8 and below, the invalid href was simply ignored, and as it turns out, this site wasn’t actually relying upon the BASE element at all.

-Eric

Update: The problems above were fixed in IE10, but a variant (where you create the A using createElement and never add it to the body) remains unfixed in IE11: https://connect.microsoft.com/IE/feedbackdetail/view/1002846/pathname-incorrect-for-out-of-document-elements#tabs