-
-
Save hidrees/76f7c0b3500f8da72ca4 to your computer and use it in GitHub Desktop.
//By default, Ghost opens links in the existing tab. Insert this in your Ghost JS file to get all your links to open in a new tab instead! | |
$('a').each(function() { | |
var a = new RegExp('/' + window.location.host + '/'); | |
if(!a.test(this.href)) { | |
$(this).click(function(event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
window.open(this.href, '_blank'); | |
}); | |
} | |
}); |
I added this in the index.js file inside the assets/js folder of my theme (casper) and it worked.
Works perfectly, thanks a lot!
Works perfectly, thanks
You can directly put this under code injection too between <script>
tags.
What must I add to make all external links nofollow?
I like more this one:
<script>
$(document).ready(function() {
$("a[href^='http']").attr("target","_blank");
});
</script>
Added in the footer of the Code Injection menu in the admin.
As, most of internal link are starting with '/', and they should be opened in the same TAB but, external links starts with http... and it is great to open them in the new TAB
You could also check this.href.indexOf(window.location.host) == -1
if it is in internal or external link.
See this blog article for more information and a detailed instruction how to use the code in Ghost and another HTML workaround for every post or page.
Thank you for the contribution.
Could you please clarify which file by name this is placed and where specifically to place it? Thank you. I have tried ghost.js but it seems to have no effect.