Click here to Skip to main content
15,891,513 members

stop watch should not reset on page unload in javascript

rahemani_1200 asked:

Open original thread
i am developing an online exam application so i used stop watch. But this stop watch is reset when page is reload or press F5 button. I don't want to reset stop watch. So please help me i am so in trouble.
My code is :



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
var msec = 0;
var sec = 0;
var min = 0;

function starttimer(){
var hdntime = document.getElementById("hdntime");
hdntime.innerHTML = min + ":" + sec + ":" + msec;
go = setTimeout("starttimer()", 1);
msec++;
if (msec == 100) {
msec = 0;
sec++;
}
if (sec == 60) {
sec = 0;
min++;
}
}
function resetwatch() {
window.location.reload();
}
</script>
</head>
<body>
<form id="form1" runat="server">

00:00:00


<input id="Button1" type="button" value="Start Watch" onclick="starttimer()"/>
<input id="Button2" runat="server" type="button" value="Stop Watch" onclick="stopwatch()" />
<input id="Button3" type="button" value="Reset Watch" onclick="resetwatch()" />


</form>
</body>
</html>
Tags: Javascript, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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