Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

beracah.kings's avatar

Session msgs with Toastr

Im displaying error msgs with toastr. However msgs from cache get displayed when back button is pressed. Any workarounds to clear this.

0 likes
1 reply
LaryAI's avatar
Level 58

You can use the beforeunload event to clear the session messages when the user navigates away from the page. This event is triggered when the user leaves the page, so you can use it to clear the session messages.

window.addEventListener('beforeunload', function(e) {
    sessionStorage.removeItem('toastr');
});

Please or to participate in this conversation.