Hello, I have a blog in wordpress where I need all external links to be opened in a new tab when clicking. But these links are loaded by ajax and the function I have is done before ajax finishes loading everything.
$(function() {
$("a[href^='http']:not([href*='zaha.in'])").each(function() {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
}).addClass('externalLink');
});
});
So I tried using javascript to set a time interval to give the jquery function time to run after the ajax finishes, however it also does not work:
// Instanciar a função
niceJavascriptRoutine = null;
// Inicio do jquery
$(document).ready(function() {
// Função jquery
function niceJqueryRoutine() {
$(function() {
$("a[href^='http']:not([href*='zaha.in'])").each(function() {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
}).addClass('externalLink');
});
});
}
// Passa a função jquery para a javascript
niceJavascriptRoutine = niceJqueryRoutine;
});
window.setInterval(niceJavascriptRoutine, 22000);
Would anyone know of any way to accomplish this after ajax loads completely? Detail that I can not edit the ajax request files because they are part of a wordpress plugin, so I would need this to happen on the outside.