0

How to show custom message in window.onbeforeunload ? By default, it is showing as attached image. I need to show Don't Refresh instead of Cancel, and Refresh Anyway instead of Leave. I have tried but failed.

Swal.fire({
                title: 'Are you sure?',
                html: 'You are about to save a session named',
                icon: 'warning',
                showCancelButton: true,
                timer: 999999,
                didOpen: () => {
                    Swal.showLoading()
                    const b = Swal.getHtmlContainer().querySelector('b')
                    timerInterval = setInterval(() => {
                        b.textContent = Swal.getTimerLeft()
                    }, 100)
                },
                willClose: () => {
                    clearInterval(timerInterval)
                },
                timerProgressBar: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Save',
                cancelButtonText: 'Continue edit'
            }).then((result) => {
                if (result.isConfirmed) {

                }
                event.preventDefault();
            });
        };
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
  • I do believe there are some browsers (depending on the version) that specifically don't allow customisation of that "before unload" prompt. You might be stuck with what you get – Craig Jul 03 '23 at 04:49

1 Answers1

0

Sadly, these days, you can't.

Most browsers do not allow it, because it was abused in the past by spammers and malware sites.

Brad
  • 159,648
  • 54
  • 349
  • 530