在 Firefox 扩展中捕获关闭选项卡事件
我正在编写一个扩展,当用户关闭此选项卡(一些保存等)时,它需要从当前选项卡/文档调用一些JS。 document.onbeforeunload 不适合我,因为它也会在页面重新加载时被调用。我正在寻找类似 tryToClose 的东西,但用于选项卡。
i'm writing a extension, which needs to call some JS from the current tab/document when user closes this tab (some saving etc). document.onbeforeunload doesn't do it for me, because it's also called when the page is reloaded. I'm looking for something like tryToClose but for tabs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要监听扩展中的“TabClose”事件,如 添加选项卡时的通知或已删除
我能够赶上该事件。有关如何防止选项卡关闭的任何指示?我尝试在处理程序代码上使用 event.stopPropagation() 。它不会停止选项卡的关闭!
You need to listen to "TabClose" event within the extension as illustrated at Notification when a tab is added or removed
I'm able to catch the event. Any pointers on how to prevent the closing of the tab? I attempted event.stopPropagation() on the handler code. It does not stop the closing of the tab!