kali ini saya akan membahas tentang code yang berisi cara membuat atau menampilakan lamanya waktu kita membuka web tersebut
misalnya anda membuaka web nah pada waktu pertama membuka makan akan ada waktu yang terus bertambah namun akan reset saat anda reload
contoh tampilan nya sperti dibawah ini :
cara membuatnya cukup simpel anda hanya perlu copy aja code dibawah ini
<html>
<head>
<title>How much time has elapsed, Since loading this web page?</title>
<Script Language="JavaScript">
// THESE TWO VARIABLES STORE THE TIME AND DATE WHEN THE PAGE IS LOADED
var startDate = new Date();
var startTime = startDate.getTime();
// THIS FUNCTION CALCULATES THE SECONDS ELAPSED SINCE THE PAGE WAS LOADED
function seconds_elapsed ()
{
var date_now = new Date ();
var time_now = date_now.getTime ();
var time_diff = time_now - startTime;
var seconds_elapsed = Math.floor ( time_diff / 1000 );
return ( seconds_elapsed );
}
// THIS FUNCTION TAKES THE SECONDS ELAPSED AND CONVERTS THEM FOR OUTPUT
function time_spent ()
{
// TAKE THE SECONDS ELAPSED
var secs = seconds_elapsed ();
// CONVERT SECONDS TO MINUTES AND SECONDS
var mins = Math.floor ( secs / 60 );
secs -= mins * 60;
// CONVERT MINUTES TO HOURS AND MINUTES
var hour = Math.floor ( mins / 60 );
mins -= hour * 60;
// DISPLAY THE FINAL OUTPUT TIME STRING
document.display.timeElapsed.value = pad ( hour ) + ":" + pad ( mins ) + ":" + pad ( secs );
// RECURSIVELY RE-RUN THE FUNCTION EVERY SECOND
setTimeout( "time_spent ()", 1000 );
}
// THIS FUNCTION INSERTS A LEADING ZERO (IF NECESSARY) TO PROVIDE UNIFORM OUTPUT
function pad ( num )
{
return ( ( num > 9 ) ? num : "0" + num );
}
</Script>
</head>
<body onLoad="time_spent()">
<center>
<h1>hitung waktu anda membuka web ini</h1>
<form name="display">
<input name="timeElapsed" type="text" size=15>
</form>
</body>
</html>
########
<head>
<title>How much time has elapsed, Since loading this web page?</title>
<Script Language="JavaScript">
// THESE TWO VARIABLES STORE THE TIME AND DATE WHEN THE PAGE IS LOADED
var startDate = new Date();
var startTime = startDate.getTime();
// THIS FUNCTION CALCULATES THE SECONDS ELAPSED SINCE THE PAGE WAS LOADED
function seconds_elapsed ()
{
var date_now = new Date ();
var time_now = date_now.getTime ();
var time_diff = time_now - startTime;
var seconds_elapsed = Math.floor ( time_diff / 1000 );
return ( seconds_elapsed );
}
// THIS FUNCTION TAKES THE SECONDS ELAPSED AND CONVERTS THEM FOR OUTPUT
function time_spent ()
{
// TAKE THE SECONDS ELAPSED
var secs = seconds_elapsed ();
// CONVERT SECONDS TO MINUTES AND SECONDS
var mins = Math.floor ( secs / 60 );
secs -= mins * 60;
// CONVERT MINUTES TO HOURS AND MINUTES
var hour = Math.floor ( mins / 60 );
mins -= hour * 60;
// DISPLAY THE FINAL OUTPUT TIME STRING
document.display.timeElapsed.value = pad ( hour ) + ":" + pad ( mins ) + ":" + pad ( secs );
// RECURSIVELY RE-RUN THE FUNCTION EVERY SECOND
setTimeout( "time_spent ()", 1000 );
}
// THIS FUNCTION INSERTS A LEADING ZERO (IF NECESSARY) TO PROVIDE UNIFORM OUTPUT
function pad ( num )
{
return ( ( num > 9 ) ? num : "0" + num );
}
</Script>
</head>
<body onLoad="time_spent()">
<center>
<h1>hitung waktu anda membuka web ini</h1>
<form name="display">
<input name="timeElapsed" type="text" size=15>
</form>
</body>
</html>
########
maka hasil nya seperti screenshot diatas tadi
selemat mencoba ya guys
Tidak ada komentar:
Posting Komentar