🌚

Davis' Alt Notes

JavaScript Snippet: Open in New Window

A tiny code block you can add to your websites, setting all external links to be opened in new windows.

<script type='text/javascript'>
    $('a').each(function() {
        var a = new RegExp('/' + window.location.host + '/');
        if(!a.test(this.href)) {
            $(this).attr("target", "_blank");
        }
    });
</script>

, — Aug 4, 2020