Home > Back-end >  Js or vue closes as how to determine the browser or refresh??
Js or vue closes as how to determine the browser or refresh??

Time:01-05

Has received a requirement is as follows:
For SpringMVC after deployment of the project, the customer access to the unified authentication platform (based on token), you need to implement a function to access the system for the first time in the browser home page, you need to perform an ajax background operation, if open the TAB, not executed many times, also does not perform refresh, but if you close all open TAB again after the first, you need to perform, that is to say every time open the home page and only one TAB opens, you need to perform a background method,

Way is: I'm going to now use localstorage to record the number of open the home page, each open a one by one, refresh don't do processing, if close a minus one, so that can only be opened again for the first time when the background method,

But now encountered a problem, is unable to determine when the browser refresh or close, find some online, but could not find the accurate approach, the main can be compatible with Google, just 360 browsers such as firefox,

Consult everybody!

CodePudding user response:

Your idea is wrong,

Even with this code, there is no guarantee that the browser will be executed correctly (animation),

Can use cookies, do not set the Max - age, under the condition of closed will delete cookies page,
So as long as the judge have cookies within the specified record is ok,

CodePudding user response:

This requirement is a little problem
The token itself has limitation? Or token is indefinitely?
Have the limitation, if a browser has none, and always on the first TAB, and then the limitation for how to refresh the token?
If indefinitely, token theft problem is bigger,
But in general this demand as 1 l said, use cookies, usually with a logout function to delete cookies,

CodePudding user response:

reference 1/f, little silly brother reply:
your idea is wrong,

Even with this code, there is no guarantee that the browser will be executed correctly (animation),

Can use cookies, do not set the Max - age, under the condition of closed will delete cookies page,
So as long as the judge if there is any specified records in a cookie,


Use cooike cannot solve the problem, if open the other pages in one browser, the page closed at this time our system, the cookie is still there, but if I log on to the system again or need to perform the backend method, but this time the cookie

CodePudding user response:

refer to the second floor qybao response:
this demand is a little problem
The token itself has limitation? Or token is indefinitely?
Have the limitation, if a browser has none, and always on the first TAB, and then the limitation for how to refresh the token?
If indefinitely, token theft problem is bigger,
But in general this demand as 1 l said, use cookies, usually with a logout function to delete cookies,


This token is certainly a failure, if failed, access to our system will intercept to the login page to login,

CodePudding user response:

You fine article,
Browser does not close, you this is not the first to open label, also do not need to perform this operation,
If you refers to the operation of the unified login token, that also is logged in, do not need to force users to log in again, time set to go,
If anyway in the operation of new user access, then you can start from access to source, if access to source is empty, indicating the user input url open, carry out the operation,
However, I still think you are thinking wrong, because when I develop this function, that is, don't shut down, that didn't quit, can also be manually,
  • Related