I felt strangely compelled to preface this page with a disclaimer, so here goes:
This page discusses MSN's Hotmail Internet mail service, arguably in an unflattering manner. Let me be clear here: I don't dislike Hotmail, it has served me well for many years now and long may that continue. They've just given me 250MB of online storage and I'm not about to diss someone who provides a free service. The following is a small personal gripe I'm only bringing up because I know one or two people who agree with me. The MSN staff have been timely and accommodating in dealing with my feedback; impressively so, when you consider how much teenage abuse [I speculate] they encounter every day.
Anyway, back to business. My gripe regards the strange things that happen to hyperlinks and plain-text URLs contained in messages displayed in Hotmail. When these links are clicked, the page will open in a new window, within a frameset with an MSN banner across the top.
Aesthetic purism aside, this can be problematic for a developer
touting his offerings to the Hotmailing world at large. (And before you
start clamouring, NO I DON'T SPAM! But I'm allowed to tell my friends,
right?) For example, one of my sites uses a script to force pages into
an iframe, but as the script only fires if the top.location and self.location properties are the same, going through Hotmail prevents that from happening.
Admittedly, in this case I could simply modify the force-frame
script to fire if the top.location isn't my intended frameset
page, but the point is that there are plenty more complex frame-topology
scripts that can't (and shouldn't have to) workaround having an extra
level of framing on top.
Client-Side
From the reader's end, it's very tricky to do anything about this. Users of the Mozilla Project's popular Firefox browser can use the Hotmail Tabs extension, whose actual purpose is to permit links to be opened in a new tab within the same browser-window.
That's something else Hotmail's links prevent in Firefox and other tabbed browsers - mouse/keyboard shortcuts to open links in a new tab are somehow disabled, to the extent that the links can't even be focused when Ctrl-clicked, middle-clicked or whatever shortcut applies. Hotmail Tabs set out to remedy this, and in the process got rid of the MSN frameset too.
This wasn't to last. Around early October 2004 - about the same time my storage grew to 250MB - the format of the links changed, so now they became JavaScript-based.
Fortunately, since Hotmail's 'internal' links (such as 'Compose') had long been JS-based, Hotmail Tabs (which already handled both types of link) was able to adapt quickly. Version 0.9, which fixes the new-style external links, was out before I finished writing this article.
I had been on this hobby-horse before I discovered Hotmail Tabs, and my prior solution had been a bookmarklet to re-rewrite the links back to normal. It went something like this:
javascript:k=document.links;
for(i=0;i<k.length;i++)
if(k[i].href.indexOf('http%')>-1)
void(k[i].href=unescape(k[i].href.split('__action=')[1]));
// Note: bookmarklets must have no line-breaks to work!
This only fixed the frame issue - the tabbing problem, I suspect, is more of a gap in the link-handling implementation whereby link hrefs rewritten by JavaScript can't be accessed by those tabbing shortcuts. No biggie - there is still a right-click option for new-tab, which does still work.
However, since Hotmail's redesign, the syntax has changed
so as to invalidate this approach. The actual URL Hotmail generates is
basically the same - the true link is urlencoded, as a parameter of the
link to the MSN frameset page. What's new is that the whole URL is wrapped
in a custom openWin() popup function.
I had several stabs at this, and got very confused by the behavior I was seeing. First approach: a modified string-paring function (similar to the above, but taking a bit off the end as well because of the JS syntax). When I ran this, I ended up with a link to the Hotmail server's cgi-bin folder, followed by a slash then the raw URL (which of course didn't go anywhere in that state). Was Hotmail deliberately thwarting my schemes?
I suspect not. More likely it's a fall-back mechanism for when a link is observed to have been wrecked anyway, so at least you get Hotmail's own error-page.
I tried another approach: instead of removing stuff, add my HotBounce URL (more on this below) as a prefix to the true URL. Although the result looked good to go, when clicked, it took me straight to the 'Message Expired' page, even when the script was executed mere seconds after reloading the message. If anyone can explain that one, I'll be most impressed.
I was down to combing the message's source code, trying to
figure out what was really going on. The openWin() function itself was
really quite basic: a choice of window.open or location.href based on
the presence of a second argument. I haven't found an example of a link
that uses this 'self' argument, but I imagine Hotmail will use it in
their own announcement emails to avoid spawning new windows. If anyone
finds an example of usage, please let me know.
I probably went through the HTML and attached scripts (even the CSS) several times, without a single clue. I don't know how many times I looked at the link syntax before I noticed a very strange quirk in the true URL - it had four characters for each escaped character! For example:
':' -> '%3a' -> '%253a'
'.' -> '%2e' -> '%252e'
It took a bit of reading to figure this one out. It turns out the characters were 'double escaped' - in effect, the extra '25' inserted was an escape of the '%' character. Apparently Firefox's status bar, where I'd previously been studying the links, hadn't been telling me the whole story. I'm still not sure how/why this was happening, but it sort of explained another anomaly. My first method, while not solving the problem, had rendered nearly the correct URL when applied twice (the only problem being that it chopped another three characters off the tail-end).
So, with this in mind I went back to the original format:
javascript:k=document.links;
for(i=0;i<k.length;i++)
if(k[i].href.indexOf('http%')>-1)
{
void(k[i].href=unescape(unescape(
k[i].href.substring(k[i].href.indexOf(
'http%'),k[i].href.length-3))));
void(k[i].target='_self');
}
// Note: had to attack the string-splitting
// differently due to the JS syntax.
Double-unescaping, sure enough, had exactly the desired effect. I had my bookmarklet, and I do hope you'll enjoy it yourself! (Don't forget to prune out those linebreak characters, though.)
BUT! it's only gonna help me in my own usage. I can't count on all my friends and correspondents to go along with all my hinky 'wierd science' ideas like bookmarklets, so how do I send them a link without them suffering the same fate?
Server-side (sort of)
Well, as I'm lucky enough to have my own corner of the World Wierd Web, perhaps somehow I could employ the power that affords me?
Now, I can't rewrite the page in someone else's browser on someone else's domain (thank goodness). But my links can drag them into my domain, and there I can do a lot. So the URL I send them just needs two components:
So I placed a page in this site's root, going by the inspired name of hotbounce.htm, to take care of step 1. If I'm using JavaScript (and on this domain I don't have any other options!) I just need the 'true URL' as a parameter, thus:
http://www.headbank.co.uk/hotbounce.htm?http://www.mozilla.org/
The 'magic' isn't really very magic at all: just a trad frame-breaker to dispel the MSN frameset. Just a few concerns that come to mind:
So, with all that in mind:
/* HotBounce script by Robin Bankhead, www.headbank.co.uk */
/* Free to reproduce but please leave this notice intact! */
function boonce() {
if (self.location.search !== '')
{
var theURL = location.search.substring(1);
top.location.href=theURL;
}
else // Just in case there's no 'true URL'
alert('Sorry, you didn\'t tell me where you\'re going!');
}
boonce();
So there you go. Merrily bounced if you need to be bounced, and treated to a luscious bit of exposition if not. Of course, if you use Firefox (and you can, on just about every platform in Christendom), Hotmail Tabs is an effective and effortless solution. But if you cling to other browsers, or have those technophobic pals you'd like to offer an au-naturel browsing experience, I hope you find some of this useful.