HN New Tab

Makes all links to posts and users open in a new tab

< Rückmeldungen aufHN New Tab

Rezension: Gut - Skript funktioniert

§
Veröffentlicht: 31.07.2015
Bearbeitet: 31.07.2015

alternative impl

I tried to use querySelectorAll to achieve the same to target the links to be opened in new tabs.

(function() {
  var filters = [
    'a',
    'not([onclick])',
    'not([target])',
    'not([class*=pocket])',
    'not([href^="#"])',
    'not([href^=mailto])',
    'not([href^=logout])'
  ],
      links = document.querySelectorAll(filters.join(':'));
  for (var i=0; i<links.length; i++) {
    links[i].setAttribute('target', '_blank');
  }
})();

Antwort schreiben

Anmelden um eine Antwort zu senden.