Internet Explorer Base HREF

Internet Explorer’s JavaScript doesn’t like the html base href element. It ignores it. This is so enragingly infuriating that I had to invent the word enragingly to encompass my enragedness (either that or it’s just not in my spellchecker). I’m pretty pissed off.

All I want is to open a new window. Pretty simple in the scheme of things. I found out the other day that the A elements target attribute is deprecated. Because opening anything in a new window is A Bad Thing and Must Not Be Done. What about this form that I’ve got on the admin section of this site I’m working on? It accepts some html tags but the people using it aren’t coders so I’ve made a link next to it that (in Firefox, Safari, Chrome and Opera) opens a small window which has some example codes which can be copied and pasted in and edited as needs be.

At this point I should add a disclaimer. Opening new windows is frowned upon and understandably so. It can be annoying if unexpected and you can end up with a load of windows cluttering your desktop. However there are times, and this is one, where a new window is exactly what you need. I specifically need two windows side by side – one to type into, one to refer to. I guess I could make a hidden div that shows when you click the link or something like that but that’s not the point, damnit!

This would work:

<a href="admin/popup.html" target="_blank">help</a>

…unless you’re using HTML 4.01 strict, in which case it will still work but you will get an error as the target attribute is deprecated (I’m actually using XHTML for some reason and despite what you might read on the internet the target attribute is still allowed in XHTML, so I’ll probably end up doing this). Also you end up with a load of toolbars and stuff taking up screen space.

But that isn’t the real problem (although removing a functionality without giving a valid alternative is pretty stupid if you ask me. And, no, in my opinion JavaScript isn’t a valid alternative because not everyone has JavaScript and I’m trying to be as accessible as possible here).

No, the real problem is with the JavaScript. What I really want is a small, neat box without any toolbars which just shows the relevant examples and leaves enough room on your screen that you can still see the window you’re typing in. So I do this:

<a href="popup.html" onclick="window.open('popup.php', '', 'scrollbars=yes, menubar=no, height=400, width=400, resizable=yes, toolbar=no, location=no, status=no'); return false;">Help!</a>

Which works great in the good browsers because they take into account the fact that popup.html is inside the admin folder, as specified by the base href. Internet Explorer, the free-spirited, anti-establishment rebel that it is does things in it’s own way. It uses the base href for relative links in the html but completely forgets about it when using JavaScript. So the above code would work fine in IE with JavaScript disabled, but try to go to “admin/admin/popup.html” when JavaScript is turned on. So either you take out the “admin/” and it breaks in the good browsers or you leave it in and it breaks on IE.

I could have spent the time I spent writing this finding a workaround but I’ve already looked and haven’t found anything so far and anyway, fuck it, it’s the admin section. The front end works on every browser imaginable and that’s good enough for me.

(Anyway, how come I could never write essays at school but I can sit down and write almost 600 words about JavaScript bugs without even thinking?)

Advertisements

About Mr Chimp

I make music, draw pictures, browse the internet, programme, and make sweet, sweet cups of tea until the early hours.
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

5 Responses to Internet Explorer Base HREF

  1. Skilldrick says:

    Could you do something like this? (in jQuery)

    var base = $('base').attr('href');
    window.open(base + 'popup.php' ...);
    

    If you’re not using jQuery, then getElementByTagname or something, but I haven’t done any old school DOM surfing like that for a long time … jQuery RULEZ!

  2. Skilldrick says:

    Alternatively, setup a subdomain on XAMPP and avoid using base altogether?

  3. Mr Chimp says:

    I have since started using jQuery and have come around to the idea of not using pop-up windows. A toggle-able div like StackOverflow and Reddit use is a better idea. I’ll leave the article as it is for posterity.

  4. Lkftcibv says:

    What are the hours of work? http://iqihygocyr.de.tl bondage girdle model Wow, I really want to be in a hot orgy like this someday!!! I liked the Panda outfit too :-D

  5. Johnd275 says:

    You are my inspiration, I possess few web logs and rarely run out from to brand. eeecgcdedfad

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s