🏠 Home 

HN New Tab

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

< Feedback on HN New Tab

Review: Good - script works

§
Posted: 2015-07-31
Edited: 2015-07-31

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');
}
})();

Post reply

Sign in to post a reply.