Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
suppose 30 min objective type online exam.

once user login and click on start exam timer start.

but if user close tab and re-open tab then this timer start again.

how can i prevent to do !

i.e user has last 10 min left and he refress page or close tab and reopen that tab
how i manage time. that it will not start from 30 min again.

i see some countdown timer but when i refress page it's start again from full time.

What I have tried:

var timer2 = "30:00";

var interval = setInterval(function () {
var timer = timer2.split(':');

//by parsing integer, I avoid all extra string processing
var minutes = parseInt(timer[0], 10);
var seconds = parseInt(timer[1], 10);
--seconds;
minutes = (seconds < 0) ? --minutes : minutes;
if (minutes < 0) clearInterval(interval);
seconds = (seconds < 0) ? 59 : seconds;
seconds = (seconds < 10) ? '0' + seconds : seconds;
//minutes = (minutes < 10) ? minutes : minutes;
$('.countdown').html(minutes + ':' + seconds);
timer2 = minutes + ':' + seconds;

if(minutes == 0 && seconds == 0)
{
alert('Exam Finished');
window.location.href = "/home/FirstQuestion";
}
}, 1000);
Posted
Updated 30-Jan-18 9:18am
v3
Comments
Mehdi Gholam 9-Jan-18 4:36am    
Store your timer elapsed time on your server or as a cookie on the client.
Jaydeep Shah 9-Jan-18 4:41am    
which is better to save elapsed time ! server or cookie ?

and have to save elapsed time every second !!??
Mehdi Gholam 9-Jan-18 4:42am    
It depends on how important your timer is.
Jaydeep Shah 9-Jan-18 4:47am    
and have to save elapsed time every second !!??
Mehdi Gholam 9-Jan-18 4:53am    
Just save the start time, you can compute the difference!

1 solution

Log the user in to the exam on the server, and record the start time there. The server then closes the exam as necessary.

server based exam timer MVC4 - Google Search[^]
 
Share this answer
 
Comments
Jaydeep Shah 18-Jan-18 6:14am    
i save start time in db. now what next i can do ?

i update my question (add Jquery counter code).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900