Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当用户单击当前浏览器选项卡的关闭按钮时,我需要获取任何事件。我在这种情况下使用的任何一种方法都不起作用(例如 onunload、unload 和 pagehide 事件处理不检测关闭选项卡,仅更改或更新选项卡)。
从Safari 文档:
卸载已弃用,请改用 pagehide。
当您单击“选项卡”视图以打开新页面时,看起来 pagehide 实际上会触发(请参阅ghenne 的答案中的此处),但除此之外,甚至不存在关闭 Mobile Safari 上的浏览器的事件!在这里和这里也找到了信息。