weixin_33736048 2010-10-08 08:34 采纳率: 0%
浏览 265

检测浏览器或标签页关闭

Is there any cross-browser JavaScript/jQuery code to detect if the browser or a browser tab is being closed, but not due to a link being clicked?

  • 写回答

21条回答 默认 最新

  • weixin_33704591 2010-10-08 08:39
    关注

    If I get you correctly, you want to know when a tab/window is effectively closed. Well, AFAIK the only way in Javascript to detect that kind of stuffs are onunload & onbeforeunload events.

    Unfortunately (or fortunately?), those events are also fired when you leave a site over a link or your browsers back button. So this is the best answer I can give, I don't think you can natively detect a pure close in Javascript. Correct me if I'm wrong here.

    评论

报告相同问题?