
What do you mean custom error message? You can only show custom message together with the default message when using onbeforeunload
in only IE 11. You can refer to this sample code.
For the second question, you can't find out which button the user clicked in onbeforeunload
so you can't trigger ajax when user presses leave.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Regards,
Yu Zhou