Answer the question
In order to leave comments, you need to log in
Is it possible to automatically make target blank for external links?
Actually a question. Is it possible to have automatic behavior for ALL external links target blank, preferably by means of HTML? It seems there was a similar tag in the head that specifies this behavior? If you can’t use HTML, then what would you advise on JS (this is probably more difficult, because Vue is used, and even the content comes via the API as JSON and is rendered via v-html)
Answer the question
In order to leave comments, you need to log in
I haven't heard that about html.
Jquery
$(document).ready(function(){
$('#content a').attr('target', '_blank');
});
window.onload = function(){
var anchors = document.getElementById('content').getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_blank');
}
}
$('#content a').each(function() {
var linky = new RegExp('/' + window.location.host + '/');
if (!linky.test(this.href)) {
$(this).attr("target","_blank");
}
});
Isn't that what you're looking for?
https://www.w3schools.com/tags/tag_base.asp
htmlbook.ru/html/base
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question