2012-04-19 4 views
2

나는 새로운 질문이있을 때 사용자에게 시간에 민감한 알림을 보내는 스크립트가 있습니다. 그러나 일부 사람들은 컴퓨터를 열어 놓고 점심을 먹고 알림이 누락 된 것으로 나타났습니다.여러 탭에서 유휴 시간을 감지 할 수 있습니까?

사용자가 5 분 동안 유휴 상태인지 여부를 감지하는 스크립트를 작성하려고합니다. 그렇다면 '오프라인'으로 표시하고 알림을 닫습니다.

탭 사이에서도 비활성 상태를 감지 할 수 있는지 궁금한가요? (예를 들어, 사용자가 Facebook.com의 다른 탭으로 전환하여 활성화 된 상태로 유지되는 경우, 웹 페이지에 구체적으로 표시되지 않은 경우에도 '활성'으로 간주됩니다).

답변

1

사용자가 옆에 없을 때 발생하는 모든 일은 추적 할 수 없습니다 (운 좋게).

이렇게하면 안됩니다 (보안에 대해 생각해보십시오).

UPDATE

는 지금은 그것을 생각. 이지만 가능하지는 않습니다. 많은 웹 사이트에서 Google 애널리틱스를 사용하기 때문에 귀하의 이름이 Google이었을 것입니다. 하지만 그 외 : 언급 된 이유 때문에 불가능합니다.

+0

하하, 맞아. 그건 의미가 있습니다. 대체 해킹을 생각해보고 같은 효과를 내기 위해 할 수있는 다른 방법을 알아 봅니다. 사용자에게 '스누즈'기능을 사용하여 30 분마다 활동하지 않는 것을 확인하도록 알릴 수도 있습니다. – Donny

1

활성 상태 일 때 데이터베이스 테이블에 마지막 활동을 저장하십시오. 마우스 이동, 키 누르기 또는 다른 활동을 사용하여 타임 스탬프를 업데이트 할 수 있습니다. 사용자가 온라인/오프라인 상태를 볼 페이지에서 ajax 호출로 해당 테이블을 주기적으로 폴링하십시오. 마지막 활성 시간이 5 분을 초과하면 오프라인이나 유휴 상태로 표시하십시오.

+0

방법에 대한에서 다른 탭을 것처럼 간다 구현? 당사 웹 사이트를 개설 한 후 사용자가 Facebook에 접속하여 활성 상태에있는 경우이를 감지 할 수 있습니까? – Donny

+0

아니요. 보안 문제가 있습니다. 다른 탭이 귀하의 은행 활동에 기웃 거리는 것이 가능하지 않기를 바랄 것입니다. 그들이 귀하의 사이트에서 활성화되어 있는지 확인할 수 있습니다. 그들은 페이스 북에 있어야 활발하지 않을 것입니다. – Buggabill

1

나는 HTML5 Visibility API 또는 fallback을 사용하여 사용자가 페이지를 떠난 다음 관찰 이벤트를 집중시키는 데 초점을 맞추고 있습니다. 브라우저 창 또는 탭의 초점을 맞출 필요가 없습니다. 페이지 열기)

하지만 비활성 상태에 대해 반응하고 싶으 시다면 ... 시간 제한을 시작할 수 있습니다. (물론 제출, 클릭, 변경 등의 이벤트가 발생하면 많은 이벤트에 글로벌 이벤트 위임이 필요합니다. mousemove 등)

0

코드는 다음과 같습니다

var inactivityTime = function() { 
    var t; 
    window.onload = resetTimer; 
    document.onmousemove = resetTimer; 
    document.onkeypress = resetTimer; 

    function logout() { 
     alert("You are now logged out.") 
     //location.href = 'logout.php' 
    } 

    function resetTimer() { 
     clearTimeout(t); 
     t = setTimeout(logout, 3000) 
     // 1000 milisec = 1 sec 
    } 
}; 
+1

코드를 사용하여 문제를 해결하는 방법을 자세히 설명해 주시겠습니까? – forsvarir

0

내 고객의 웹 사이트에이 기능을 구현하고 싶었다. 내 코드를 나뭇 가지했다 web.Finally이에 대한 idleal 해결책을 찾기 일부러 어떤 논리 생각하고 이걸 봐 코드 below--

 `/*Put this code inside script tag whereever you want to execute the inactivity popup*/ 
    var t; 
    //set the timeout period 
    var timeoutPeriod = '${inactiveIntervalMillis}'; 
    //detect various events 
    callUserEvents(); 
    ` 

//remove the logged Out storage after popup is closed by user 
function removeLocalStorage() { 
localStorage.removeItem("loggedOut"); 
}  
//call this function whenever we detect user activity 
function resetUserActivity() { 
resetTimer(); 
} 
//If the user is logged out and it clicks on other tabs,the popup will be    displayed there too 
function checkIfUserLoggedOut() { 
    if (localStorage.getItem("loggedOut")) { 
     loadLoginModal("/includes/gadgets/popup-content.jsp", 400, 230, 
      undefined); 
    } 
} 

// Call this method when any window onloads,this helps to check if multiple   tabs are opened by same site 
function incrementCounter() { 
    checkIfUserLoggedOut(); 
    if (localStorage.getItem("counter") == "NaN") { 
     localStorage.setItem("counter", "0"); 
    } else { 
     var counter = parseInt(localStorage.getItem("counter")) + 1; 
     localStorage.setItem("counter", counter); 
    } 
    resetTimer(); 
} 
//after time interval,this method will be called 
function handleIdleTimedOut() { 
//get the current localStorage Object 
    window.sharedCounter = localStorage.getItem("counter"); 
//If no tabs are opened,then popup will be shown here. 
    if (window.localCounter == window.sharedCounter) { 
     loadLoginModal("/includes/gadgets/popup-content.jsp", 400,    230,undefined); 
     localStorage.setItem("loggedOut", "true"); 
    } 
} 

function resetTimer() { 
//save counterin current Window object,and after timeout period you can  match it,if by chance multiple tabs were opened,the counter will be  different,popup wont be shown in current window at incorrect time. 
    window.localCounter = localStorage.getItem("counter"); 
    clearTimeout(t); 
    t = setTimeout(handleIdleTimedOut, timeoutPeriod); 
} 
function callUserEvents(){ 
window.onload=incrementCounter 
window.onscroll = resetUserActivity; 
window.onmousemove = resetUserActivity;  
window.ondblclick = resetUserActivity; 
window.oncontextmenu = resetUserActivity; 
window.onclick = resetUserActivity; 
window.onkeypress = resetUserActivity; 
window.onpageshow = resetUserActivity; 
window.onresize = resetUserActivity; 
window.onfocus = incrementCounter; 
window.ondrag = resetUserActivity; 
window.oncopy = resetUserActivity; 
window.oncut = resetUserActivity; 
window.onpaste = resetUserActivity;  
} 

` 
관련 문제