Use link.protocol instead of link.href.indexOf.