Well, considering it’s being read in Javascript, it’s possible to do this in several ways:
- With regular expressions
This option tends to be more laborious, after all before you had a problem (change the src of the images) and now you will have two (change src and use regular expressions). Fortunately Javascript treats ER’s as first-class entities.
function ajustaSrcER() {
var expReg = /src=(("[^"]+")|('[^']+'))/igm;
var texto = $(".Result").innerHTML;
$(".Result").innerHTML = texto.replace(expReg, function(match, p1, p2, p3, offset, s) {
return "src=" + p1.replace("http://exemplo.com","http://meudominio.com");
});
}
- Manipulating the DOM
Another option is to manipulate the DOM (Document Object Model). Considering that it is possible to use the Jquery library we can do so:
// funcao que busca todos os img's e altera seus src's
function ajustarSrc() {
$(".Result img").each(function() {
var src = $(this).prop("src");
$(this).prop("src", src.replace("http://exemplo.com","http://meudominio.com"));
});
}
In both cases this should be performed immediately after loading. This can be achieved by including a function in the $.load call:
$.load(" coloque a sua url aqui ", function() {
// Acao a ser executada depois do carregamento
});
Is the loading done in PHP or Javascript? Depending on the answer the solution changes.
– Robson França
javascript
– SowberScripts