2
Hello, I have a wordpress blog 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 executed 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 through javascript to set a time interval to give time to run the jquery function after ajax finished, however 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 any way to accomplish this after the ajax fully loads? Detail that I can not edit the files of the ajax request because they are part of a wordpress plugin, then I would need this to occur outside.
did not work, yet after ajax is loaded it does not assign the target
– Felipe Lima