2016-08-26 4 views
-1

要件続けるボタンをクリックした場合にリセットします。チェックユーザーがポップアップ非アクティブショーで、彼はjavascriptの

  1. ユーザーがアクティブでない場合は、5分後にポップアップが表示されます。選択されたセッションが継続されると、タイマーはこのためにリセットされ、同じことを再度チェックする。

  2. ユーザーが[続行]ボタンをクリックしていない場合は、ページが更新されます。

+0

http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browserを経ます-window-is-not-currently-active –

答えて

0

どのように非アクティブであるかをチェックしますか?

キーボードとマウスの両方にイベントをつなぎ、マウスが移動/クリックまたはキーダウンするたびにタイマーをリセットできます。

のjQueryを使用して
0
<body onmousemove = "canceltimer()"; onclick = "canceltimer()"> 

var tim = 0; 
function reload() 
{ 
tim = setTimeout("location.reload(true);",180000); // 3 minutes 
} 
function canceltimer() 
{ 
window.clearTimeout(tim); // cancel the timer on each mousemove/click 
reload(); // and restart it 
} 
0

$(function() { 
     (function handleInactivity() { 
      var maxIdleTime = 5000; // 5 seconds 
      var timeout = setTimeout(displayPopup, maxIdleTime); 

      function resetTimer() { 
       console.log("Timer reset"); 
       clearTimeout(timeout); 
       timeout = setTimeout(displayPopup, maxIdleTime); 
      } 

      function displayPopup() { 
       console.log("You're up"); 
       // Display popup of your choice 
      } 

      $(document).on("mousemove", resetTimer); 
      $(document).on("mouseDown", resetTimer); 
      $(document).keypress(resetTimer); 
     })(); 
    }); 
+0

回答ありがとうございます私は自分の要件に従って改善しました –

0
_inactiveUserPopUp = function(warningTime,PageReloadTimeAfterWaring){ 

     var maxIdleTime = warningTime *1000,timeout,resetTimer,displayPopup,pageReload; 

      timeout = setTimeout(displayPopup, maxIdleTime); 

      resetTimer = function(){ 
      // console.log("Timer reset"); 
      clearTimeout(timeout); 
      timeout = setTimeout(displayPopup, maxIdleTime); 
     }; 

      displayPopup = function(){ 
       //console.log("You're up"); 
      clearTimeout(timeout); 
      var reloadPage = setTimeout(pageReload, PageReloadTimeAfterWaring*1000); 

      $(".modalDialog").css({ 
       "opacity": 1, 
       "display": "block" 
      }); 

      $(".close").on("click", function() { 
       $(".modalDialog").css({ 
        "opacity": 0, 
        "display": "none" 
       }); 
      }); 

      $("#extend-session").off().on("click", function() { 

       clearTimeout(reloadPage); 

       $(".modalDialog").css({ 
        "opacity": 0, 
        "display": "none" 
       }); 

       $.ajax({ 
        url: $("#openModal").data("ajaxUrl"), 
        type: "POST", 
        data: { 
         activeUser: true 
        }, 
        success: function(data) { 

        } 
       }); 

      }); 
     }; 

     pageReload = function(){ 
       //console.log("reload page now") 
      $(document).off("mousemove"); 
      $(document).off("mouseDown"); 
      $(document).off("keypress"); 

      window.location.reload(); 
     }; 

     $(document).on("mousemove", resetTimer); 
     $(document).on("mouseDown", resetTimer); 
     $(document).keypress(resetTimer); 

    }; 
関連する問題