Reputation: 149
This function doesn't open links in a new window in Edge. Works in all other browsers. Not sure what the problem is:
function externalLinks() {
for (var c = document.getElementsByTagName("a"), a = 0; a < c.length; a++) {
var b = c[a];
b.getAttribute("href") && b.hostname !== location.hostname &&
(b.target = "_blank")
}
};
externalLinks();
Upvotes: 2
Views: 180
Reputation: 781721
Change
b.hostname !== location.hostname
to
(b.hostname || b.href.hostname) !== location.hostname
Modern browsers have the properties of the href
in the anchor element. If it's not there, this will try to access it from the href
property.
Upvotes: 3