How does js listen for browser closes and make pop-up prompts?

I have done the upload / download function, and now I want to achieve: when the upload / download is not completed, click to close the browser, the pop-up file is downloading / uploading, are you sure to close?

Jul.08,2021

refer to the API documentation.

window.onbeforeunload-Web API API | MDN- https://developer.mozilla.org.

the general idea is:

  • registers a closed window listening event for window when downloading / uploading
  • Log out of the listening event of this closed window after download / upload

how to solve the problem


window.onunload = function(){
 alert('?')
}
Menu