Showing the custom confirm window after canceling onbeforeunload module window in Chrome

Viewed 81

I have such situation:

  1. The form is opened on tear-off window

  2. There are unsaved changes

  3. Window is being closed

In these circumstances, I need to display a standard module window, enter image description here

and if the user clicks "Cancel", then custom confirm window should appear enter image description here

But in Chrome the icon on the confirm window doesn't appear enter image description here

On Firefox and on IE the icon appears under the same circumstances.

Code of 'onbeforeunload' event:

window.addEventListener('beforeunload', function (e) {
    // function where the confirm window is formed
    showConfirmWindow();

    return e.returnValue = window.getResource('', 'ex.unsaved_changes');
});

The path to the image is correct because this window is used not only here and the image is displayed. It is only in Chrome and only in such circumstances. I guess that Chrome saves resources because the window closes - so why pull up the icon. But maybe someone knows how to fix it for Chrome?

Additional information: if add timeout on 0 ms for function where the confirm window is formed - the icon is shown

window.addEventListener('beforeunload', function (e) {
    // function where the confirm window is formed
    setTimeout(showConfirmWindow, 0);

    return e.returnValue = window.getResource('', 'ex.unsaved_changes');
});

But this is a bad decision.

0 Answers
Related