Code:
if (!anchors[i].getAttribute("href").match(("example")))
The trouble here is that this matches only when the href attribute contains "example", which it often won't.
HTML Code:
<a href="page_2.html">next page</a> this will open as an external link.
There is a bug in IE, where getAttribute('href') returns the absolute URL rather than the actual href attribute, which is why this code works in that browser, but according to the DOM the getAttribute() function must return the actual value of the attribute, reasonably enough.
There are two ways to work around IE's incorrect implementation of the standard, one is to use a magical second argument to getAttribute(), which means, "if you are IE please follow the standard," and the other would be to use .href instead of .getAttribute('href'). The .href property returns the absolute URL in every case according to DOM 2 HTML, and is implemented correctly even by IE.
So either of these might work:
Code:
if(anchors[i].getAttribute('href',2).match('^http://'))
if(!anchors[i].href.match('example.com/'))
Matching against ^http:// (the ^ matches the beginning of the string) is the cleanest and doesn't need to be modified to work on other sites. It won't work, of course, if there are absolute URLs to other pages on the same site.
EDIT after reading post #3:
Since you have absolute URLs on the same domain, unless you can change them, you'll have to use .href and look for the actual domain.