1

On page reload i have to show the message "File upload in progress, your upload will be lost on reload!". I am using the below code for that, but the alert is always "Changes that you made may not be saved!" in chrome browser.

window.onbeforeunload = function() {
   return 'File upload in progress, your upload will be lost on reload!';
}
Amala James
  • 1,336
  • 3
  • 16
  • 32
  • 4
    Possible duplicate of [How can I override the OnBeforeUnload dialog and replace it with my own?](http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own) – David R Aug 22 '16 at 07:57
  • You need to set the event's `.returnValue` property with the text instead of returning it. Weird, I know, but that's what the spec says. [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload) – Whothehellisthat Aug 22 '16 at 08:10

1 Answers1

0

You need to set the event's .returnValue property with the text instead of returning it. Weird, I know, but that's what the spec says. MDN

window.onbeforeunload = function(event) {
   event.returnValue = 'File upload in progress, your upload will be lost on reload!';
}
Whothehellisthat
  • 2,072
  • 1
  • 14
  • 14