0 Followers
0 Following
1 Posts

open external links in a new tab

https://lemmy.world/post/1348861

open external links in a new tab - LemmyWorld

I wrote a quick script that opens links to external sites in a new tab. It works everywhere, not just on lemmy.world. You need a browser extension to embed custom javascript to use it. document.addEventListener('click', evt => { const href = (evt.target?.tagName === 'A' ? evt.target : evt.target?.closest('a'))?.getAttribute('href'); if (href && !href.startsWith(location.origin) && href.match(/^(?:https?:)?\/\//)) { window.open(href, '_blank'); evt.preventDefault(); } });