javascript - js code to obtain verification code countdown problem
漂亮男人
漂亮男人 2017-07-05 10:50:31
0
3
944

When getting the verification code countdown (for example, the countdown is at 40s), I click the link to go to another page (_self, this page jumps, no new tab is opened). After a period of time, I click the back button and return to the countdown. On the page, the countdown still starts from 40s.

The desired effect is that the countdown will continue to move according to the actual event. For example, if I stay for 20s, the countdown should be at 20

when I come back.

Excuse me, is there any solution? (The js of the new page that jumps cannot be modified)

漂亮男人
漂亮男人

reply all(3)
三叔

Use code similar to this to store the time when the verification code is sent in sessionStorage, and subtract it from the current time:

var sentTime = new Date().getTime();
sessionStorage.setItem('sentTime', sentTime);
console.log(sentTime);
var timePassed;
setInterval(function(){
    timePassed = (new Date().getTime() - sessionStorage.getItem('sentTime')); 
    console.log(timePassed);
},1000);
学习ing

The countdown is saved in localstorage. Every time you go to this page, read it from localstorage first

滿天的星座

You can save the current state to sessionStorage.

But in fact, you should return to the state where you have not clicked to obtain the verification code, and then make a judgment when you click again.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template