const urlSearchParams = new URLSearchParams(window.location.search); const params = Object.fromEntries(urlSearchParams.entries()); src = 'https://alp.safer.fr/alertes-pub'; // add task if defined if (params.task) { src += '/' + params.task; } // add query params let queryParams = []; queryParams.push('originDomain='+window.location.hostname); if (params.token) { queryParams.push('mailtoken=' + params.token); } src += '?' + queryParams.join('&'); // create iframe DOM element iframe = document.createElement('iframe'); iframe.src = src; iframe.setAttribute('style', 'width:100%; border:none;overflow: clip;'); iframe.setAttribute('scrolling', 'no'); // append iframe to container const div = document.getElementById('alertespubcontainer'); div.appendChild(iframe); window.addEventListener('message', function(e) { // message that was passed from iframe page let message = e.data; switch (message.command) { case 'resize': iframe.style.height = message.height + 'px'; break; case 'reload': window.location.reload(); break; } } , false);