To remove the “OK” button from a SweetAlert dialog using JavaScript, you can customize the SweetAlert options.
To do this we can write
Swal.fire({
title: 'Custom HTML title',
html: 'I will close in <strong></strong> milliseconds.',
timer: 2000,
timerProgressBar: true,
showConfirmButton: false, // Remove the "OK" button
allowOutsideClick: false, // Prevent the dialog from closing by clicking outside
allowEscapeKey: false // Prevent the dialog from closing by pressing the escape key
});
In this code, showConfirmButton: false
removes the “OK” button from the SweetAlert dialog.
timer
specifies the duration (in milliseconds) after which the dialog will automatically close.
timerProgressBar: true
displays a progress bar indicating the remaining time before the dialog closes.
allowOutsideClick: false
and allowEscapeKey: false
prevent the user from closing the dialog by clicking outside or pressing the escape key, respectively.
Adjust the SweetAlert options according to your specific requirements.
This configuration will create a dialog that automatically closes after a specified duration without requiring any user interaction.