You can capture the browser's back button by listening to the popstate
event. This event is triggered when the active history entry changes.
Example:
window.addEventListener('popstate', function(event) {
console.log('Back button was pressed');
});
Tags: intermediate, JavaScript, Browser Events