|
Page Details >>>
When someone visits your web page, JavaScript will start the clock. When the leave that page, they will be alerted with the time they have been viewing the page!
Add the below code to the <body> section of your page:
<script
language="javascript"
type="text/javascript">
pageOpen
=
new
Date();
function
bye()
{
pageClose
=
new
Date();
minutes
=
(pageClose.getMinutes()
-
pageOpen.getMinutes());
seconds
=
(pageClose.getSeconds()
-
pageOpen.getSeconds());
time
=
(seconds
+
(minutes
*
60));
if
(time
==
1)
{
time
=
(time
+
" second");
}
else
{
time
=
(time
+
" seconds");
}
alert('It
has been '
+
time +
'. Please stay longer next
time!');
}
window.onunload
=
bye;
</script>
|
|