WEB-DEVELOPMENT-APPLICATIONS practice question 12 of 25

Which History API object is called when a browser window’s document history changes?

Full set: 131 questions
Answer options
A: Window, location
B: Window, onpopstate Correct answer
C: Window, name
D: Window, open
Correct Answer:
B. Window, onpopstate
Explanation

The popstate event is dispatched to the window object every time the active history entry changes. The window.onpopstate property is the event handler that is called to process these popstate events. This occurs when the user navigates with the browser's back and forward buttons or when JavaScript calls history.back(), history.forward(), or history.go(). Therefore, window.onpopstate is the specific API member called when the document history changes.

Why Incorrect

A. window.location is an object providing URL information and methods for navigation; it is not an event handler for history changes.
C. window.name is a property for getting or setting the name of the window's browsing context, unrelated to history events.
D. window.open() is a method used to open new browser windows, not an event handler that responds to history navigation.

References

1. MDN Web Docs. (2023). Window: popstate event. Mozilla. Retrieved from https://developer.mozilla.org/en-US/docs/Web/API/Window/popstateevent. (This document explicitly states the popstate event is fired when the history entry changes).

2. MDN Web Docs. (2023). Window.onpopstate. Mozilla. Retrieved from https://developer.mozilla.org/en-US/docs/Web/API/Window/onpopstate. (This page defines onpopstate as the event handler for the popstate event).

3. WHATWG. (2023). HTML Living Standard. Section 8.8.3 "The PopStateEvent interface". Retrieved from https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-popstateevent-interface.

Scroll to Top