Doesn't work in IE

Discussion in 'JavaScript' started by qwikad.com, Jul 8, 2019.

  1. #1
    This little function opens links in a new window in all browsers except IE / Edge:
    
    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();
    
    Code (markup):
    Does anyone know why?
     
    qwikad.com, Jul 8, 2019 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,291
    Likes Received:
    1,698
    Best Answers:
    31
    Trophy Points:
    475
    #2
    Got it working by changing b.hostname to b.href.hostname
     
    qwikad.com, Jul 8, 2019 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Probably WAY too late, but did you REALLY mean to assign b.target to __blank, or is that supposed to be ==?
     
    deathshadow, Jul 31, 2019 IP