Tell me, there is input . It is necessary to catch an event when data entry in the field is completed. This event will update the record in the database and remove the lock. Input is considered complete, the user clicked outside the field on this page, well, or clicked the tab . In general, off the record. I cannot do the button, it is necessary to process the field.

The problem is that onchange , like focusout , works if you leave the tab or minimize the browser. I understand that with these actions, the field focus is probably lost and onchange launched. But if the window opens back to the page with the field, the field has a focus and a carriage where it was when it was folded, and this gives hope that something can be done.

How can you get out of the situation, is there any way not to trigger the event when the browser is minimized?

Thank!

    1 answer 1

    I only managed to delay the processing of the event as follows:

     // Можем ли мы производить действие (да или нет) var canTakeAction = true; // Обработчик события, вызываемый через малое время function takeAction() { if (canTakeAction) { console.log("We take action") } } // Общая функция для изменения видимости function handleVisibilityChange(newValue) { canTakeAction = newValue; } // Если у нас вкладка поменялась document.addEventListener("visibilitychange", function () { if (document.hidden) { handleVisibilityChange(false); } else { handleVisibilityChange(true); } }); // документ доступен document.addEventListener('focus', function (evt) { handleVisibilityChange(true); }, false); // документ теряет фокус document.addEventListener('blur', function (evt) { handleVisibilityChange(false); }, false); //окно доступно window.addEventListener('focus', function () { handleVisibilityChange(true); }, false); // окно теряет фокус window.addEventListener('blur', function () { handleVisibilityChange(false); }, false); 
     <!-- Вызываем обработчик события через малое время, чтобы глобальные события уже отработали --> <input onblur="setTimeout(takeAction,100)"> <!-- --> 

    • Many thanks for the answer, it turned out interesting. I am now trying to go the other way: just handle click outside the field and pressing tab. Tomorrow I will also describe in the form of an answer. Then try your method. Although the delay is small, I still would not want to. - Maxim Stepanov