 Hey, everyone. It's Sam here. Sometimes your users will leave your page, but what if they're still in the middle of an operation, like submitting a form or uploading a file? In this episode, I'm going to show you the standard way to warn a user that they're closing your page. Let's begin. [? BAM, BAM, BAM, BAM, BAM. ?] When a user closes your page or follows a link to a different page, which is kind of like closing your page, your JavaScript has a chance to intercept this and warn your user via the before-unload event. Let's take a look. So here is the simplest example. We can add a listener in the before-unload event and return a message. You have to give a message, because old browsers will display it verbatim. But newer browsers will actually override this to a very generic one about, changes may not be saved. Either way, this will prompt the user, are you sure you want to close me? But we know that a page which always warns you it's going to be closed is going to be incredibly frustrating for your users. So you should add a condition to only pop up the dialogue when you might lose some data, like a network request is still in transit or a form is unsubmitted. What I suggest is to use unfinished promises. For example, every time you do a network fetch, you get back a promise, like this. We can write a method which adds that promise to a set of pending operations. If anything is in that set, we still have operations we're waiting for, so we can make sure to block the page from unloading. Then we add a method to the promise for when it's done, which removes it from the set. The same set could control the display of a busy spinner. This is a really neat way to remind your users that something is working, and that they'll learn that closing your page during that time will prompt them to wait. I also want to cover a special case. Modern browsers have a method called send beacon, which lets you send a network request without waiting for a response. You fire the request and forget about it. It's really useful for analytics events, and if it suits your needs, you won't need to block your users until it completes. It's actually designed to run even after a page is closed. Be sure to check out the extended article where we explain this topic in a bit more depth, and we have some code snippets for you to use. So remember, use the before and load event to prompt the user. Use a set to keep track of unfinished business on your page, and use send beacon for fire and forget network requests. That was unloading the page the standard way. See you on the next tip. I've got my processor off. It's very important.