Jump to content

Time spend on website

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
mkgr

mkgr

    Newbie

  • Members
  • Pip
  • 4 posts
Hi.
I would like to add to my site a counter which shows how may hours(minutes) they are at each page.
I have already found a code , but in order to see the time , you have to click the button.
The code is that:

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

day = new Date();

miVisit = day.getTime();

function clock() {

dayTwo = new Date();

hrNow = dayTwo.getHours();

mnNow = dayTwo.getMinutes();	

scNow = dayTwo.getSeconds();

miNow = dayTwo.getTime();

if (hrNow == 0) {

hour = 12;

ap = " AM";

} else if(hrNow <= 11) {

ap = " AM";

hour = hrNow;

} else if(hrNow == 12) {

ap = " PM";

hour = 12;

} else if (hrNow >= 13) {

hour = (hrNow - 12);

ap = " PM";

}

if (hrNow >= 13) {

hour = hrNow - 12;

}

if (mnNow <= 9) {

min = "0" + mnNow;

}

else (min = mnNow)

if (scNow <= 9) {

secs = "0" + scNow;

} else {

secs = scNow;

}

time = hour + ":" + min + ":" + secs + ap;

document.form.button.value = time;

self.status = time;

setTimeout('clock()', 1000);

}

function timeInfo() {

milliSince = miNow;

milliNow = miNow - miVisit;

secsVisit = Math.round(milliNow / 1000);

minsVisit = Math.round((milliNow / 1000) / 60);

alert(" "

+ "You have spent " + milliNow + " milliseconds on this page.  "

+ ".... About " + minsVisit + " minutes, and "

+ secsVisit + " seconds.");

}

document.write("<form name=\"form\">"

+ "<input type=button value=\"Click for info!\""

+ " name=button onClick=\"timeInfo()\"></form>");

onError = null;

clock();

// End -->

</SCRIPT>


Though i've noticed that the seconds arent displayed correclty.
How can i make it to display it as text(not as clickable button) and to the position i want?

Thanks in advance!

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Insteading of document.writing() the code for a button, just output the text.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
mkgr

mkgr

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks,
i did that , but the time isnt auto-updated so it says "You have spent 0 milliseconds on this page. .... About 0 minutes, and 0 seconds. " and then it remains the same.
Any idea how to do it to be updated each second that passes?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You would need some kind of loop to rerun the code.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You can use a timer to update it every second.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
mkgr

mkgr

    Newbie

  • Members
  • Pip
  • 4 posts
what's the code i should write then?

#7
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Do some of your own research, I'm not going to do everything for you. Research timers.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#8
rhoan

rhoan

    Newbie

  • Members
  • PipPip
  • 11 posts
yeah try search other resources... theres a lot of timer script in the web