User login timed out, how to pop up the login prompt box instead of jumping to the login interface?

in the current company"s ERP system, when the user page is open, you will need to log in again after a period of time due to session timeout, and jump to the login page.
but if the user is editing form data and the login timed out and refreshed directly, it will cause all the data that has been written for half a day to be gone.
so it is hoped that the login status can be determined before the user"s operation, and if it times out, the login box will pop up.

the current method is to use AJAX to determine whether the user is logged in when submitting the form, and then pop up the login box.
is there any other way to monitor globally (including the jump of forms and links) so that the login prompt will pop up as long as the user is operating during login timeout?

Mar.02,2021

you can write a global variable, visit the file every 3 seconds, and write your judgment in it.


it is not recommended to change the login box, which may partially affect the existing logic.
the front-end page can add a function: a timer is written on the page, which is triggered when the form is edited, and the form content is cached regularly to the client (browser); read the cache when entering the page, and restore if there is any content.


when submitting the form, you can cache the data first, and then determine whether the user's login expires when AJAX submits the information. If so, jump to the login page after completing the login, return to the original page, read the cache and repopulate the page


get the client mark a time after logging in token, and then start a timer. When the token is about to expire, the timer can execute the pop-up window.

Menu