B
blankito1998
Beta
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
$(document).ready(function() {Es probable que el problema esté en que al eliminar elsrcdeotherIframe, el navegador deja de cargar el contenido del iframe, lo que podría causar que el DOM no se actualice como esperas antes de intentar agregar el "lagger".
### Solución
Para resolver esto, puedes intentar modificar el orden de las operaciones. Primero, asegúrate de que estás agregando el "lagger" antes de eliminar elsrc. Aquí tienes cómo podrías ajustar tu código para hacerlo:
1. Primero, añade el "lagger".
2. Luego, elimina elsrcdel iframe.
### Código Modificado
Aquí hay un ejemplo ajustado:
JavaScript:if (currentJores) { if (otherIframeDataId !== currentJores) { // Aquí se agrega el lagger const container = $(".freimps" + otherIframeDataId); if (container.length > 0) { // Verificar si el lagger ya existe antes de agregarlo if (container.find(".laggs[dataid='" + otherIframeDataId + "']").length === 0) { console.log("Agregando lagger para: ", otherIframeDataId); container.prepend( '<div class="laggs" dataid="' + otherIframeDataId + '" style="margin-left:10px;display:flex;justify-content:center;align-items:center;background:#000000;width:calc(100% - 20px);height:100%;position:absolute;"><img src="../wpp/img/loading-25.gif" loading="lazy" style="width:20px;height:20px;" /></div>' ); } } // Eliminar src solo después de agregar el lagger otherIframe.removeAttribute('src'); // Eliminar el src de otros iframes } }
### Resumen de Cambios
- Agregar el "lagger" antes de eliminar el
src. Esto permite que el "lagger" se inserte en el DOM antes de que el iframe deje de estar activo.- Mantén el resto de la lógica que ya tienes para manejar los casos donde no aparece
jores.
### Paso para Probar
- Prueba este ajuste para ver si resuelve el problema. Asegúrate de que el "lagger" se inserta correctamente antes de que el navegador maneje la eliminación delsrcen el iframe.
Si el problema persiste, sigue haciendo debugging conconsole.logpara verificar el flujo del código y los valores de las variables en cada paso. ¡Hazme saber cómo te va!
const options = {
root: null,
threshold: 0.6
};
let observer3 = new IntersectionObserver((entries) => {
entries.forEach(entry => {
const dataId = entry.target.getAttribute('dataid');
const iframe = entry.target;
if (entry.isIntersecting) {
// Asignar src si está vacío
if (!iframe.src || iframe.src === "") {
iframe.src = iframe.getAttribute("data-src");
iframe.onload = function() {
$(".laggs[dataid='" + dataId + "']").remove();
attachScale3ClickListener(iframe, dataId);
};
}
// Limpiar src de otros iframes
document.querySelectorAll(".sessim .octumpro[data-src]").forEach(otherIframe => {
const otherIframeDataId = otherIframe.getAttribute("dataid");
const currentJores = $("subody[jores]").attr("jores");
// Eliminar src y agregar lagger si jores está presente
if (currentJores) {
if (otherIframeDataId !== currentJores) {
otherIframe.removeAttribute('src'); // Eliminar el src de otros iframes
// Verificar si el lagger ya existe antes de agregarlo
if ($(".freimps" + otherIframeDataId + " .laggs[dataid='" + otherIframeDataId + "']").length === 0) {
console.log("Agregando lagger al iframe: ", otherIframeDataId); // Debug
$(".freimps" + otherIframeDataId).prepend(
'<div class="laggs" dataid="' + otherIframeDataId + '" style="margin-left:10px;display:flex;justify-content:center;align-items:center;background:#000000;width:calc(100% - 20px);height:100%;position:absolute;"><img src="../wpp/img/loading-25.gif" loading="lazy" style="width:20px;height:20px;" /></div>'
);
}
}
} else { // Si no está presente, eliminar el src y agregar el lagger a otros iframes
if (otherIframeDataId !== dataId) {
otherIframe.removeAttribute('src'); // Eliminar el src de otros iframes
// Verificar si el lagger ya existe antes de agregarlo
if ($(".freimps" + otherIframeDataId + " .laggs[dataid='" + otherIframeDataId + "']").length === 0) {
console.log("Agregando lagger a iframe sin jores: ", otherIframeDataId); // Debug
$(".freimps" + otherIframeDataId).prepend(
'<div class="laggs" style="margin-left:10px;display:flex;justify-content:center;align-items:center;background:#000000;width:calc(100% - 20px);height:100%;position:absolute;" dataid="'+otherIframeDataId+'"><img src="../wpp/img/loading-25.gif" loading="lazy" style="width:20px;height:20px;" /></div>'
);
}
}
}
});
}
});
}, options);
function attachScale3ClickListener(iframe, dataId) {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
// Usar delegación de eventos para el botón .scale3 en el iframe
$(iframeDocument).on('click', '.scale3', function() {
$("subody").attr("jores", dataId);
});
}
function observeLogamDivs2() {
document.querySelectorAll('.sessim .octumpro[data-src]').forEach(elem => {
if (elem instanceof Node) {
observer3.observe(elem);
}
});
}
observeLogamDivs2();
let mutationObserver3 = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1) {
const iframes = node.querySelectorAll('.sessim .octumpro[data-src]');
iframes.forEach(iframe => {
if (iframe instanceof Node) {
observer3.observe(iframe);
}
});
}
});
});
});
const targetNode = document.querySelector('.moreinfo');
if (targetNode) {
mutationObserver3.observe(targetNode, {
childList: true,
subtree: true
});
}
// Manejar el evento de salida de pantalla completa
document.addEventListener('fullscreenchange', (event) => {
if (!document.fullscreenElement) {
// Vuelve a cargar el src para los iframes visibles
document.querySelectorAll(".sessim .octumpro[data-src]").forEach(iframe => {
const dataId = iframe.getAttribute('dataid');
$("subody").removeAttr("jores");
$(".laggs[dataid='" + dataId + "']").remove();
});
}
});
});
agrega el codigo aqui


