Dustin H
Dustin H

Reputation: 85

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.

Upvotes: 1

Views: 5963

Answers (1)

Cody Bonney
Cody Bonney

Reputation: 1658

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

Working Example

Upvotes: 5

Related Questions