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,