1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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?
    SEMrush
     
    qwikad.com, Jul 8, 2019 IP
    SEMrush
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    5,852
    Likes Received:
    1,085
    Best Answers:
    22
    Trophy Points:
    400
    #2
    Got it working by changing b.hostname to b.href.hostname
     
    qwikad.com, Jul 8, 2019 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,924
    Likes Received:
    1,625
    Best Answers:
    232
    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