Open External links on the new window on your ghost publication
Ghost opens every external URL in the same page by default. A lot of you want every external link should open in a new window so that your readers don't distract from your content. & currently, there is no option in ghost to open external links in a new window.
To do that we have prepared a small javascript snippet. With this small javascript snippet, all your external links will open in a new window. to do that follow the steps
- From Ghost admin go to Setting > Code Injection
- At the Site Footer section paste the following codes
<script>
const anchors = document.querySelectorAll('a');
for (x = 0, l = anchors.length; x < l; x++) {
const regex = new RegExp('/' + window.location.host + '/');
if (!regex.test(anchors[x].href)) {
anchors[x].setAttribute('target', '_blank');
anchors[x].setAttribute('rel', 'noopener');
}
}
</script>
- Hit the save button at the top right corner
Once the page is saved, all your external links will be open in a new window.
I hope you find this helpful.