you need to Address this by binding a Document Visibility Tracker. Here's a sample function and you can add more actions like popup, warning or ending something as per your requirement.
To Bind it, add the JS to your form and bind it to OnLoad and OnSave Events like this
Function:
var ActivityTracking = {
init: function() {
console.log("Initializing Activity Tracking with visibilitychange");
document.addEventListener("visibilitychange", function() {
if (document.hidden) {
ActivityTracking.userLeftTab();
} else {
ActivityTracking.userReturnedToTab();
}
});
},
userLeftTab: function() {
console.log("User has navigated away from the tab.");
// Add any additional behavior you want here, like tracking or alerts
},
userReturnedToTab: function() {
console.log("User has returned to the tab.");
// Add any additional behavior you want here, like tracking or alerts
}
};
ActivityTracking.init();