Rory Primrose

I don't have a solution but I admire the problem

Recent Posts

Tags

Community

Email Notifications

Archives

Fix the BASE tag, break me

The IEBlog has just posted an entry about the behaviour of the BASE tag in IE7. The standard (back to HTML 3.2) says that the base tag should occur once in the document and it should be located in the HEAD tag. The IE implementation for the last few versions has been that references and links will be relative to the last BASE tag specified. IE7 will remove this behaviour to be more standards compliant.

While I agree with standards compliance, this one will hurt. I have built a feed reader application that displays entries that have been obtained from different sites. It is quite common that when people write their blog entries, they include relative references to images and hyperlinks.

I have used the IE BASE tag behaviour to get around the broken link problem that my feed reader would otherwise have. For each entry that I render from XML to HTML, I prefix it with a BASE tag that specifies the base href being the url of the web version of the post. As any relative image and anchor urls would be relative to that page, my feed reader was causing IE to correctly identify all the resource for the entries regardless of the site they came from.

How do I get around this? Any ideas?

Without any nice implementation provided already, I will have to parse the contents of each entry, determine the links that are relative and prefix them with the web address for the entry. Quite ugly.

I don't mind if they revert the BASE tag implementation to be more standards compliant. It would have been nice if the IE team provided another way to declare a section of HTML as relative to a base url though.

Comments

Daniel F said:

One hackish solution I can think of off the top of my head is to use IFrames. They can be made to look almost like they're not there, and you could probably DOM script the contents in, creating a BASE link in the HEAD of the iframe's document as you go.

Nifty use of the BASE tag tho, full points for the workaround :)
# August 30, 2005 9:38 AM

Rory Primrose said:

Hi Daniel,

That is a good idea. Didn't think of that. I would have to test what the performance would be like when there are a few hundred entries in the page though.

I can't really take the credit for the idea of using the BASE tag that way. Geoff was the one who knew about the behaviour.

Hey Geoff, get me out of this one!
# August 30, 2005 8:54 PM

Daniel F said:

Heh, performance will probably nosedive, IE will have a cow when trying to render 200 iframe's.

In terms of manually parsing the HTML, it should be relatively easy to regexp find any A and IMG tags, pretty sure I've seen something similair... I need google for my brain :-)
[10 mins later]
Yep, Jeff Attwood has such a beast for his MHTBuilder, details are at http://www.codinghorror.com/blog/archives/000245.html. I don't fully grok regexp's myself, so can't guarantee they'll work, but I've used MHTBuilder and it rocks hardcore.

Good luck :-)
# August 31, 2005 1:39 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)