var urlSitioScript = "https://eco.e3stores.com/widgets"; var cliente = localStorage.getItem('cliente'); const link2 = document.createElement('link'); link2.rel = 'stylesheet'; link2.type = 'text/css'; link2.href = urlSitioScript+'/'+'e3eco_Common.css'; document.head.appendChild(link2); const link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = urlSitioScript+'/'+cliente+'.css'; document.head.appendChild(link); // Función para cargar el contenido de un archivo HTML async function cargarContenido(url) { const respuesta = await fetch(url); const contenido = await respuesta.text(); return contenido; } fetch(urlSitioScript+'/'+cliente+'.json') .then(response => { // Verificar si la solicitud fue exitosa (código de estado 200) if (!response.ok) { throw new Error('La solicitud no fue exitosa'); } // Parsear la respuesta como JSON return response.json(); }) .then(data => { // Hacer algo con los datos JSON console.log('Datos cargados:', data); cargarContenido(urlSitioScript+'/e3eco_Widget-header.html').then(contenido => { const bannerScriptHeader = document.getElementById('e3Eco_Widget-Header'); if (bannerScriptHeader) { bannerScriptHeader.innerHTML = contenido; // Modificar el atributo href después de insertar el contenido var enlaceModificado = document.getElementById('e3Eco-js-LandingLink-header'); var svgElement = document.querySelector('#e3Eco-js-Image-header'); enlaceModificado.href = data.url; svgElement.innerHTML = data.img; } }); cargarContenido(urlSitioScript+'/e3eco_Widget-site.html').then(contenido => { const bannerScriptSite = document.getElementById('e3Eco_Widget-Site'); if (bannerScriptSite) { bannerScriptSite.innerHTML = contenido; // Modificar el atributo href después de insertar el contenido var enlaceModificado = document.getElementById('e3Eco-js-LandingLink-site'); var svgElement = document.querySelector('#e3Eco-js-Image-site'); enlaceModificado.href = data.url; svgElement.innerHTML = data.img; } }); cargarContenido(urlSitioScript+'/e3eco_Widget-site-cart.html').then(contenido => { const bannerScriptCart = document.getElementById('e3Eco_Widget-Cart'); if (bannerScriptCart) { bannerScriptCart.innerHTML = contenido; // Modificar el atributo href después de insertar el contenido var enlaceModificado = document.getElementById('e3Eco-js-LandingLink-cart'); var svgElement = document.querySelector('#e3Eco-js-Image-cart'); enlaceModificado.href = data.url; svgElement.innerHTML = data.img; } }); cargarContenido(urlSitioScript+'/e3eco_Widget-site-thanks.html').then(contenido => { const bannerScriptThanks = document.getElementById('e3Eco_Widget-Thanks'); if (bannerScriptThanks) { bannerScriptThanks.innerHTML = contenido; // Modificar el atributo href después de insertar el contenido var enlaceModificado = document.getElementById('e3Eco-js-LandingLink-thanks'); var svgElement = document.querySelector('#e3Eco-js-Image-thanks'); enlaceModificado.href = data.url; svgElement.innerHTML = data.img; } }); cargarContenido(urlSitioScript+'/e3eco_Widget-shipping.html').then(contenido => { const bannerScriptShipping = document.getElementById('e3Eco_Widget-Shipping'); if (bannerScriptShipping) { bannerScriptShipping.innerHTML = contenido; // Modificar el atributo href después de insertar el contenido var enlaceModificado = document.getElementById('e3Eco-js-LandingLink-shipping'); var svgElement = document.querySelector('#e3Eco-js-Image-shipping'); enlaceModificado.href = data.url; svgElement.innerHTML = data.imgShipping; } }); }) .catch(error => { // Manejar errores en la solicitud console.error('Error de carga de datos:', error); });