Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   Javascript (http://siteownersforums.com/forumdisplay.php?f=24)
-   -   JavaScript setTimeout (http://siteownersforums.com/showthread.php?t=100039)

artijain1900 07-24-2013 10:43 PM

JavaScript setTimeout
 
Hello guys,

Can anyone tell me here that how can i use setTimeout() function in JavaScript in my project???

jordan_rap13 09-26-2013 12:05 PM

look at this example:

var dayarray=new Array("Sunday","Monday","Thusday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){
var currentTime = new Date();

var day=currentTime.getDay();
var day_month = currentTime.getDate();
if (day_month<10){
day_month="0"+day_month;
}
var month = currentTime.getMonth();
var year = currentTime.getFullYear();

var hours=currentTime.getHours();
var minutes=currentTime.getMinutes();
var seconds=currentTime.getSeconds();

var last="am";
if (hours>=12){last="pm";}
if (hours>12){hours=hours-12;}
if (hours==0){hours=12;}

if (minutes<=9){minutes="0"+minutes;}
if (seconds<=9){seconds="0"+seconds;}

var ddate=dayarray[day]+" "+day_month+" "+montharray[month]+" "+year+", "+hours+":"+minutes+":"+seconds+" "+last;

$(".date_time").html(ddate);

setTimeout("getthedate()",1000);
}

So the final line, will run the getthedate function every 1000ms (1 sec)

alligatortek001 03-11-2014 12:33 AM

For example:

var heartbeat = function (data) {
if (!heartbeatInterval) {
// no heartbeat
return;
}

var obj = Package.encode(Package.TYPE_HEARTBEAT);
if (heartbeatTimeoutId) {
clearTimeout(heartbeatTimeoutId);
heartbeatTimeoutId = null;
}

if (heartbeatId) {
// already in a heartbeat interval
return;
}

heartbeatId = setTimeout(function () {
heartbeatId = null;
send(obj);

nextHeartbeatTimeout = Date.now() + heartbeatTimeout;
heartbeatTimeoutId = setTimeout(heartbeatTimeoutCb, heartbeatTimeout);
}, heartbeatInterval);
};

var heartbeatTimeoutCb = function () {
var gap = nextHeartbeatTimeout - Date.now();
if (gap > gapThreshold) {
heartbeatTimeoutId = setTimeout(heartbeatTimeoutCb, gap);
} else {
console.error('server heartbeat timeout');
pomelo.emit('heartbeat timeout');
pomelo.disconnect();
}
};

simar 04-09-2014 11:00 PM

set Timeout
 
Thanks for coding of javascript set timeout

artijain1900 12-04-2014 04:03 AM

Thanks all of you guys for solving my query.

vkachuliak 12-14-2014 10:48 AM

For any action that has to be done after some time

niel 12-28-2014 01:22 PM

thanks for explaining

Rajesh S 01-16-2015 11:59 AM

thank you..


All times are GMT -7. The time now is 01:08 PM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.