Prevent automatic page refresh with SweetAlert

2.4k Views Asked by At

I have several pages on my website that refresh the pages after a function using javascript or sometimes turbolinks and even action cable.

I want to use SweetAlert to display information but its not very helpful because it displays right before a refresh so it is only visible for a quick moment.

Based on previous stack overflow questions I have constructed this:

      Swal.fire({
        title: 'Sweet!',
        text: `You got the ${data.badge.description} badge!`,
        imageUrl: data.badge_image_url,
        imageWidth: 200,
        imageHeight: 200,
        imageAlt: 'Custom image'
        },
        function(isConfirm) {
          if (isConfirm) {
            window.location.reload();
          }
        });

However, it does not seem to fix the issue.

1

There are 1 best solutions below

0
On

You Can try something like this:

Swal.fire({
  title: 'Your message',
  icon: 'info',
  confirmButtonText: 'OK'
}).then(function(){
  window.location.reload();
})