I have two tab. One is home tab and another one is home-1 tab. Here i tracking the time count for login to logout time. I have following code in one java script file. this work as two instance.
home tab -> www.example.com/home //(my java script file contain this directory) first instance.
home-1 tab -> www.example.com/home-1 //(required script file include from home tab into this tab) second instance.
Any key/mouse event will reset the counter.
var sestmout=0;
var idletm=60*1;
var idletmcntr=0;
var idletimeout=null;
var lastUpdate1 = new Object();
var lastUpdate = 0;
var curdttm = new Date();
$(document).ready(function(){
initidletm();
});
lastUpdate1.cntr = idletmcntr;
lastUpdate1.ctme = curdttm.getMilliseconds();
lastUpdate1.time = curdttm.getTime();
function reset_cnt(){
if(idletmcntr != 0){
curdttm = new Date();
lastUpdate1.cntr = idletmcntr;
lastUpdate1.ctme = curdttm.getMilliseconds();
lastUpdate1.time = curdttm.getTime();
var a = moment();
lastUpdate1.utme = a.valueOf();
}
idletmcntr=0;
}
document.onclick=function(){
reset_cnt();
};
document.onmousemove=function(){
reset_cnt();
};
document.onkeypress=function() {
reset_cnt();
};
In each tab I include above lines in java script file. Now I trigger the mouse/key event on home tab that reset counter value in home-1 tab.
Using this code.
function initidletm(){
if(window.name == "home-1"){
window.opener.document.onkeypress = document.onkeypress;
window.opener.document.onclick = document.onclick;
window.opener.document.onmousemove = document.onmousemove;
}else if(window.name == "home-2"){
window.opener.document.onkeypress = document.onkeypress;
window.opener.document.onclick = document.onclick;
window.opener.document.onmousemove = document.onmousemove;
}
else{ // home tab
document.onkeypress=function() {
reset_cnt();
};
document.onclick=function() {
reset_cnt();
};
document.onmousemove=function() {
reset_cnt();
};
}
}
clearTimeout(idletimeout);
idletimeout=setTimeout(trackidletm,1000);
function trackidletm() {
initidletm();
}
This approach is write or wrong. Only home tab reset the counter value to the home-1 and other tabs. The other tabs like home-1 tab does not reset the home tab and other tabs. What reason? And How to reset the other tab counter value from working tab?