Detect Mobile Browser Close Event
Asked Answered
G

2

7

Is there any way to detect mobile browser close event? I need to forcefully delete a cookie on browser close. I have already tried my luck with window.onbeforeunload and window.unload but they doesn't work for mobile browsers. Search on the web a lot but didn't get any solution.

Thanks in advance

Gaiter answered 11/2, 2015 at 8:54 Comment(8)
set a cookie with a past expires time ?Heroism
Are you killing the browser tab ?Mallemuck
@Heroism I need to do that after I get the close event.Gaiter
This wouldn't work anyway. What if I just pulled the battery? Ask yourself this: If I don't want the data to be persistent, should I really be storing it in a cookie?Acervate
@RGraham Its kinda flag kind thing which I need across all the pages. I am not storing any dataGaiter
What about a session cookie then? This question is worth a readAcervate
@AnkurAggarwal, why after the close event ? the browser will remove this cookie when the tab will be closed I guess.Heroism
@AnkurAggarwal you can use localstorage or sessionstorage in javascript to set and access data across webpages for a single session..Complexity
K
3

I'm sorry but it's just impossible with Javascript... You can prevent the action of closing tab but not to do something when it will be close...

How to Detect Browser Window /Tab Close Event?

Kierkegaardian answered 11/2, 2015 at 9:0 Comment(0)
A
2

Use $(window).blur(function() for mobile browsers.

Annihilation answered 28/4, 2017 at 6:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.