Alert not re-appearing after reloading or refreshing webpage

I need somebody to enlight me or guide me to where or how I could make this alert to not re-appear after the user reloads their webpage, but rather store it as a cookie or simply re-enable it after they open or close their browser/app. https://getbootstrap.com/docs/5.2/components/alert
4 Replies
13eck
13eck3y ago
Session storage might be what you're looking for: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
• Whenever a document is loaded in a particular tab in the browser, a unique page session gets created and assigned to that particular tab. That page session is valid only for that particular tab. • A page session lasts as long as the tab or the browser is open, and survives over page reloads and restores. • Opening a page in a new tab or window creates a new session with the value of the top-level browsing context, which differs from how session cookies work. • Opening multiple tabs/windows with the same URL creates sessionStorage for each tab/window. • Duplicating a tab copies the tab's sessionStorage into the new tab. • Closing a tab/window ends the session and clears objects in sessionStorage.
Or if you use localStorage to keep the state persisted across multiple tabs you can use the beforeunload event on the window to remove the state from local storage: https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event This event is what codepen, for example, uses to say "are you sure you want to leave?" when you try to close the window or navigate away when there are unsaved changes
Myndi
MyndiOP3y ago
Thanks! I will take a look into the documentation :)
13eck
13eck3y ago
👍
Myndi
MyndiOP3y ago
(and maybe come back if I'm dumb enough)
Want results from more Discord servers?
Add your server