I need to run a function when a user closes a tab or browser window containing a Suitelet.I have been attempting to incorporate a variation of the following code that works in the console but I can't get it to work in my Suitelet:
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Any string';
}
// For Safari and Chrome
return 'Any string';
}