admin管理员组

文章数量:1335598

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

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

Share Improve this question asked Feb 11, 2015 at 8:54 Ankur AggarwalAnkur Aggarwal 3,1015 gold badges33 silver badges57 bronze badges 8
  • set a cookie with a past expires time ? – Hacketo Commented Feb 11, 2015 at 8:58
  • Are you killing the browser tab ? – Mukesh Agarwal Commented Feb 11, 2015 at 8:59
  • @Hacketo I need to do that after I get the close event. – Ankur Aggarwal Commented Feb 11, 2015 at 9:00
  • 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? – CodingIntrigue Commented Feb 11, 2015 at 9:00
  • @RGraham Its kinda flag kind thing which I need across all the pages. I am not storing any data – Ankur Aggarwal Commented Feb 11, 2015 at 9:02
 |  Show 3 more ments

2 Answers 2

Reset to default 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?

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

本文标签: javascriptDetect Mobile Browser Close EventStack Overflow