I want to have a time limited offer displayed on stage 1 of a checkout process. The timer will be set at, for example, 5 minutes and should start when the page is first loaded. If they leave the page and then return to it, the timer needs to continue counting down from the initial activation, not start again.
Is anyone aware of a script for this function using php and javascript? If not, some advice on how to achieve this would be great. I can create a timer without too much problem, but no idea how to get it to trigger only on first page load and then maintain the count.
I have already implemented this type of functionality. In my scenario, student has to pass some specified time before go to next chapter. For that we are showing timer to student and at the back-end we are saving elapsed time every five second to database using ajax. So if student has pass the time 17 seconds and then leave the page. So next time when he will come to that chapter timer will start from 15 second, which was saved to database then again start to record the elapsed time to database every 5 second.
You want more details. Please tell me.
Thanks, Amit Prajapati
You can resolve this storing the datetime of the first visit on server or client side.
On the client side, you can use the localStorage
to save the datetime the first time the page is loaded. The next time the page is visited, you check in the localStorage if the datetime variable is set, and compare this value with the current time to show the timer.
If you are not worried about a change on this value (there is not side effects if the client modifies or delete this value on the localStorage) I'll take this approach.
But if this timer is a Domain concern (you want to track the datetime), you have to store this value on the server side.