i am making an interviewing chatbot using programO (i am new to php) in which i want to display a message if for long time there is no activity on chat window. i hav searched jquery plugins but they are for detecting mouse or keyboard strokes but i am just concerend with detecting that whether the chat window is upadted with a user input or not . i hav also searched javascript settimeout and settimeinterval functions to display a message but i am unable to understand how to use them with chat window form.
setTimeout needs to be used in conjunction with clearTimeout. Use clearTimeout whenever a time resetting event occurs.
Example:
<script>
var interval = -1;
var TIMEOUT = 5; // seconds
function doTimeout(){
alert('show timeout message');
startClock(); // if you want to restart the timer
}
function startClock(event){
console.log("foo",interval, event);
if(interval !== -1){
console.log("clearing timeout");
clearTimeout(interval);
}
interval = setTimeout(doTimeout,TIMEOUT*1000);
}
startClock(); // if you want to start the timer on arrival
</script>
<!-- add remove events as you see fit -->
<textarea id="chatinput" onblur="startClock(event)" onfocus="startClock(event)" onchange="startClock(event)" onkeyup="startClock(event)"></textarea>
For more on timeout:
tags: settimeoutsetinterval
questions: javascript setTimeout clearTimeout