You cannot control when user will refresh the web page and close it, but it’s important sometimes to display a confirmation alert before closing the Tab.
The user may be mistakenly clicked the close button and lost some important data.
You have seen in Shopping websites when you are in the middle of payment or you are paying the Bill and if you try to refresh the web page then it will show a confirm alert on the screen.
When is it Required?
- When the form has many fields and the user filled the form but somehow the Browser is being closed. Now, the user needs to again fill that long-form.
- While student giving the online test and not completed yet and try to close or refresh the page.
- There are many other situations where you can use it.
In this post, I discuss How you can detect Browser Tab close and refresh using JavaScript.



