Thursday, June 4, 2009

Unhelpful IE8 JavaScript Fixups

The following lines of javascript work in every browser that I know of with the exception of IE8.

function e(u,d){
a=u+'@'+d;
document.write('<a href="mailto:'+a+'">'+a+'</a>');
}


The function is designed to obfuscate email addresses, an email harvesting bot would have to run the page through a JavaScript engine or know the layout. However IE8 seems to think that the variable "a" has some special meaning. The code in IE8 produces the following HTML:

<a href="mailto:http://server/dir/user@dom">http://server/dir/user@dom</a>

In every other browser I've tested it produces the following:

<a href="mailto:user@dom">user@dom</a>

Changing the variable a to something else or scoping it with var a; works. It also works in IE8 compatibility mode. I couldn't find any documentation for this "feature" yet.