Search code examples
javascripthtmlwindow

Confirm window close


I am creating an HTML printable quiz and test maker and I would like to confirm "Are you sure you want to close this window?" when the user attempts to close the window. If they click ok it closes, but if they click cancel it does not.

I need this to work in IE and Chrome.


Solution

  • window.onbeforeunload = function(e) {
        return 'some prompt text';
    };
    

    Working Example