B
blankito1998
Beta
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
$(document).ready(function() {Si el evento de clic en el elemento con la clase.scale3no se está detectando, podría deberse a que el iframe no está accediendo correctamente a su contenido, o el evento no se está asignando adecuadamente. Vamos a implementar una técnica alternativa para asegurarnos de que los eventos se asignen incluso si el iframe se recarga.
### Modificaciones Sugeridas:
1. Delegar el evento al contenedor del documento principal: En lugar de intentar acceder al documento del iframe, podemos delegar el evento a un elemento padre. Esto funciona incluso si el iframe se recarga.
2. UtilizarsetTimeoutpara asegurar que el contenido esté completamente cargado antes de asignar el evento.
Aquí tienes el código ajustado:
JavaScript:$(document).ready(function() { const options = { root: null, threshold: 0.6 }; let loadTimeouts; 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(); // Elimina el lagger al cargar // Asegurarse de que el evento se asigne después de que el iframe se haya cargado setTimeout(() => { // Usar un escuchador en el documento principal $(document).on('click', '.scale3', function() { $("subody").attr("jores", dataId); // Asigna el valor de dataId a jores }); }, 100); // Tiempo de espera para asegurarse de que el contenido esté completamente cargado }; } // Controlar y limpiar src de otros iframes clearTimeout(loadTimeouts); // Limpiar el timeout anterior loadTimeouts = setTimeout(() => { document.querySelectorAll(".sessim .octumpro[data-src]").forEach(otherIframe => { const otherIframeDataId = otherIframe.getAttribute("dataid"); // Limpiar el src de otros iframes if (otherIframeDataId !== dataId) { $(otherIframe).removeAttr('src'); // Añadir el mensaje de carga, si no existe if ($(".laggs[dataid='" + otherIframeDataId + "']").length === 0) { $(".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>' ); } } }); }, 300); } else { // Detener la limpieza si el iframe no es visible clearTimeout(loadTimeouts); } }); }, options); 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); // Asignar el src nuevamente si es necesario al volver a observar if (!iframe.src || iframe.src === "") { iframe.src = iframe.getAttribute("data-src"); iframe.onload = function() { $(".laggs[dataid='" + iframe.getAttribute('dataid') + "']").remove(); // Eliminar el lagger // Usar un escuchador en el documento principal setTimeout(() => { $(document).on('click', '.scale3', function() { $("subody").attr("jores", iframe.getAttribute('dataid')); }); }, 100); // Tiempo de espera para asegurarse de que el contenido esté completamente cargado }; } } }); } }); }); }); 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) { const currentJores = $("subody").attr("jores"); document.querySelectorAll(".sessim .octumpro[data-src]").forEach(iframe => { const dataId = iframe.getAttribute('dataid'); // Limpiar el src de otros iframes y el lagger if (dataId !== currentJores) { $(iframe).removeAttr('src'); $(".laggs[dataid='" + dataId + "']").remove(); // Eliminar el lagger correspondiente } else { iframe.src = iframe.getAttribute("data-src"); // Restablecer el src para el que tiene jores } }); $("subody").removeAttr("jores"); // Elimina el atributo jores del subbody } }); });
### Resumen de Cambios:
1. Delegar el evento: En lugar de intentar asignar el evento de clic directamente al iframe, se asigna al documento principal usando$(document).on(...). Esto permite que el evento se maneje incluso si el iframe se recarga.
2. Uso desetTimeout: Asegura que el evento de clic se asigne después de que el iframe esté completamente cargado. Esto puede ayudar a prevenir problemas donde el evento se intenta asignar antes de que el contenido esté disponible.
### Pruebas:
- Verifica el contenido: Asegúrate de que el elemento con clase
.scale3esté presente y disponible en el iframe.- Depuración: Si no funciona, consulta la consola del navegador para ver si hay errores o advertencias.
Si sigues teniendo problemas, haremos más ajustes. ¡Avísame!
const options = {
root: null,
threshold: 0.6
};
let loadTimeouts;
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);
};
}
// Controlar y limpiar src de otros iframes
loadTimeouts = setInterval(() => {
const iframes = document.querySelectorAll(".sessim .octumpro[data-src]");
iframes.forEach(otherIframe => {
const otherIframeDataId = otherIframe.getAttribute("dataid");
const currentJores = $("subody").attr("jores"); // Obtener el valor del atributo jores
if (otherIframeDataId !== dataId && otherIframeDataId !== currentJores) {
// Comprobar si no existe el elemento .laggs con el dataid correspondiente
if ($(".laggs[dataid='" + otherIframeDataId + "']").length === 0) {
$(otherIframe).removeAttr('src'); // Eliminar el src de otros iframes
// Prepend para agregar mensaje de carga
$(".freimps" + otherIframeDataId).prepend(
'<div class="laggs" dataid="' + otherIframeDataId + '" style="margin-left:10px;display:flex;justify-content:center;justify-items:center;align-content:center;align-items:center;background:#000000;width:calc(100% - 20px);height:100%;float:left;z-index:1;position:absolute;"><img src="../wpp/img/loading-25.gif" loading="lazy" style="width:20px;height:20px;" /></div>'
);
}
}
});
}, 300);
} else {
clearInterval(loadTimeouts);
}
});
}, 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);
// Aquí puedes agregar la lógica que quieras
});
}
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);
// Asignar el src nuevamente si es necesario al volver a observar
if (!iframe.src || iframe.src === "") {
iframe.src = iframe.getAttribute("data-src");
iframe.onload = function() {
$(".laggs[dataid='" + iframe.getAttribute('dataid') + "']").remove();
attachScale3ClickListener(iframe, iframe.getAttribute('dataid'));
};
}
}
});
}
});
});
});
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, si es necesario, para los iframes visibles
document.querySelectorAll(".sessim .octumpro[data-src]").forEach(iframe => {
const dataId = iframe.getAttribute('dataid');
if (iframe.src === "") { // Verifica solo si el src está vacío
iframe.src = iframe.getAttribute("data-src");
$(".laggs[dataid='" + dataId + "']").remove();
}
});
// Eliminar el atributo jores del subbody
$("subody").removeAttr("jores");
}
});
});
mm aqui si me funciona bien la funcion de scale3, combina los 2


