One small/tiny change: could you move var-definition out of if-block, since it's used outside of this block? Legal according the js syntax, but might confuse people refactoring the code. You may think placing targetHref presence check in the isInternalLink expression, e.g. `isInternalLink = targetHref && (targetHref.replace...`