WEB-DEVELOPMENT-APPLICATIONS practice question 17 of 25

Which event occurs when a user closes a browser?

Full set: 131 questions
Answer options
A: submit
B: unload Correct answer
C: abort
D: reset
Correct Answer:
B. unload
Explanation

The unload event is fired on the window object when the document is being unloaded. This process occurs when a user navigates away from the current page, which includes actions like clicking a link to another page, submitting a form, or closing the browser window or tab. It is traditionally used for cleanup tasks, though modern APIs like pagehide are now recommended for better reliability.

Why Incorrect

A. submit: This event is fired on a element when the user clicks a submit button or presses Enter, not when the browser closes.
C. abort: This event is fired when the loading of a resource (e.g., an image) has been aborted by the user, not when the browser window closes.
D. reset: This event is fired on a element when the user clicks a reset button, clearing the form's inputs.

References

1. Mozilla Developer Network (MDN). (2023). Window: unload event. In Web APIs. Retrieved from https://developer.mozilla.org/en-US/docs/Web/API/Window/unloadevent

2. WHATWG. (2024). HTML Living Standard. Section 8.1.5.5 "The unload event". Retrieved from https://html.spec.whatwg.org/multipage/browsing-the-web.html#event-unload

3. W3C. (2016). UI Events. Section 5.5 "Focus Events". (While this document focuses on UI events, it helps differentiate event types like unload from form-specific events like submit and reset). Retrieved from https://www.w3.org/TR/uievents/

Scroll to Top