I am wondering if it is possible to detect whether the user exits the Chrome browser?
EDIT - Sorry, I wasn't being very clear so I'll explain my situation. I am storing some variables in the browser's localstorage. When the user closes the browser, I want to delete some of these variables.
A tab or window closing in a browser can be detected by using the beforeunload event. This can be used to alert the user in case some data is unsaved on the page, or the user has mistakenly navigated away from the current page by closing the tab or the browser.
We can manage this functionality via beforeunload event. To find the browser or tab close event can be identfied by using 'onbeforeunload' event in javascript and in jQuery can use 'beforeunload' event.
A. The procedure for closing all open Chrome browser tabs has changed over the years, but on most recent Android tablets, press down on the “x” on the end of any open tab. Leave your finger on the tab until the Close All Tabs option appears on screen and then select that option to shut down all of the open pages.
You can hook the OnBeforeUnload
event of the window
<script type="text/javascript">
$(window).bind('beforeunload', function() {
if (iWantTo) {
return "Don't leave me!";
}
});
</script>
Or create a JavaScript timer that pings your sever every XX seconds. When the pings stop, you can assume the user has closed the browser or navigated away.
http://ajaxpatterns.org/archive/Heartbeat.php
They have lots of good stuff in their documentation. onRemoved
of the window object would seem to do it.
https://developer.chrome.com/docs/extensions/reference/windows/#event-onRemoved
Or perhaps you mean tabs. In which case the onRemoved
for the tab object would do it.
https://developer.chrome.com/docs/extensions/reference/tabs/#event-onRemoved
API Index
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With