KANAjetzt / guessThePrice_Back

Invite your friends and guess the price of random amazon products!
https://www.preiseraten.de/
0 stars 0 forks source link

Add onbeforeunload - to prevent accidentally closing the game tab #74

Open KANAjetzt opened 3 years ago

KANAjetzt commented 3 years ago

handle it with svelte:window

MDN Page

However, unlike the unload event, there is a legitimate use case for the beforeunload event: the scenario where the user has entered unsaved data that will be lost if the page is unloaded.

It is recommended that developers listen for beforeunload only in this scenario, and only when they actually have unsaved changes, so as to minimize the effect on performance. See the Examples section below for an example of this.

So I can listen for this event while the player is in game and remove it as soon as the game is finished.