Acabo de crear una función que muestra un cuadro de diálogo en la página en Javascript, esta función es asíncrona porque carga el cuadro de diálogo que es una página en PHP. Sin embargo, para mostrar el mensaje necesito pasar parámetros. Esta función funciona muy bien, pero no funciona en absoluto en Safari, cuando muestro los parámetros, en Safari devuelve "indefinido", mientras que en MS Edge devuelve los valores de los parámetros. Probé con otra función no asíncrona y muestra bien los parámetros. ¿Crees que Safari no maneja parámetros para funciones asíncronas o lo estoy haciendo mal? Muchas gracias a la gente que me va a ayudar. (Perdón por mi mal ingles).
Función :
async function openDialogInfo(title, message, button) { alert(title + ' ' + message + ' ' + button); var title = (typeof title !== 'undefined') ? encodeURI(title) : 'Information'; var message = (typeof message !== 'undefined') ? encodeURI(message) : 'Error retrieving message !'; var button = (typeof button !== 'undefined') ? encodeURI(button) : 'Ok'; if (title.length >= 3 && message.length >= 5 && button.length >= 3) { if (screen.width >= 720) { $("#out-popup-e").css({ 'opacity': '0' }).show(); } else { $("#out-popup-e").show(); } var params = `title=${title}&message=${message}&bouton=${button}`; var resp = await fetch('../../../popup/popup_ecars_info.php', { method: "POST", body: params, headers: { "Content-type": 'application/x-www-form-urlencoded' } }); var out = await resp.text(); if (resp.status == '200') { if (screen.width >= 720) { $("#out-popup-e").animate({ 'opacity': '1' }, 400).html(out); } else { $("#out-popup-e").html(out); $(".center-popup").css({ 'bottom': '-700px' }).animate({ 'bottom': '0' }, 400); } } else { console.error('Error Message 2'); } } else { console.error('Error message 1'); } } <button class="action" onclick="openDialogInfo('HELLO WORLD', 'New message for testing (don\'t work on Safari)')">TEST</button> <button class="no-action" onclick="autreTest('New Message (work)')">New test</button>El problema es que estás declarando nuevas variables con los mismos nombres que los parámetros. Dado que se declaran con var , las declaraciones se elevan a la parte superior de la función y el valor indefinido inicial anula los parámetros.
Use diferentes variables o simplemente reasígnelas en lugar de volver a declararlas.
async function openDialogInfo(title, message, button) { alert(title + ' ' + message + ' ' + button); title = (typeof title !== 'undefined') ? encodeURI(title) : 'Information'; message = (typeof message !== 'undefined') ? encodeURI(message) : 'Error retrieving message !'; button = (typeof button !== 'undefined') ? encodeURI(button) : 'Ok'; if (title.length >= 3 && message.length >= 5 && button.length >= 3) { if (screen.width >= 720) { $("#out-popup-e").css({ 'opacity': '0' }).show(); } else { $("#out-popup-e").show(); } var params = `title=${title}&message=${message}&bouton=${button}`; var resp = await fetch('../../../popup/popup_ecars_info.php', { method: "POST", body: params, headers: { "Content-type": 'application/x-www-form-urlencoded' } }); var out = await resp.text(); if (resp.status == '200') { if (screen.width >= 720) { $("#out-popup-e").animate({ 'opacity': '1' }, 400).html(out); } else { $("#out-popup-e").html(out); $(".center-popup").css({ 'bottom': '-700px' }).animate({ 'bottom': '0' }, 400); } } else { console.error('Error Message 2'); } } else { console.error('Error message 1'); } } <button class="action" onclick="openDialogInfo('HELLO WORLD', 'New message for testing (don\'t work on Safari)')">TEST</button> <button class="no-action" onclick="autreTest('New Message (work)')">New test</button>