简体   繁体   中英

Firefox Extension: close event on popup

guys!

I am writing web extension for Firefox.

I need to handle close event on popup window of extension (specifically, like beforeClosed) to save data, which user set in form.

How can I do this?

You can use

window.addEventListener("unload", function(){
  console.log("save your data");
});

Source: Firefox Extension - onPopupClose event?

YMMV, but the accepted answer did not work for me. The 'unload' event never fired. What did work was 'blur', placed in a JS file that is loaded by the popup HTML file.

window.addEventListener('blur', function (event) {
  console.log('Window closing.');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM