In my previous blog I have explained how to Prevent Internet Explorer from caching http calls so that each time you can get fresh data from the server. Here is its link: Prevent Internet Explorer from caching http calls
Now in this blog, I will let you know how to detect browser window close action. Now this action may be sometimes required where you want to perform some kind of function on window close. Say you may be required to call Logout function on a secured website. Now this functionality can be done by the following line of javascript code
<html>
<head>
<title>Hello</title>
<script type="text/javascript" language="Javascript">
function DetectBrowserExit() {
alert('Here you can execute task you want');
}
window.onbeforeunload = function() {
DetectBrowserExit();
}
</script>
</head>
<body>
Close this browser to notice the browser close event
</body>
</html>
And if we talk about its browser compatibility, I have tested this in following browsers:-
- Google Chrome
- Internet Explorer
- Mozilla Firefox
- Safari
Thats all for now.
THANKS
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Kamaldeep Singh
Kamaldeep is a highly skilled Backend Developer specializing in Java, specifically the Spring framework. He also has extensive knowledge of Javascript and associated frameworks such as Node.js and Express. He possesses a deep understanding of the latest technologies and has hands-on experience with Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as both relational databases like MySQL and PostgreSQL and non-relational databases like MongoDB. He has made significant contributions to various projects, including Viral Nation, ExamWorks, TNIBRO, Biogas engineering, SecureNow - Web Application, FB Messenger Chatbot, Dialogflow Chatbot, and Catalyst. Kamaldeep's expertise allows him to seamlessly integrate different technologies into applications, highlighting his adaptability and innovative mindset. His practical experience and strong technical skills make him an invaluable asset to any team.