2016-06-21 8 views
0

このjqueryプラグインhttp://www.paulirish.com/2009/jquery-idletimer-plugin/が見つかりました。x秒後に自動リダイレクトが発生しました。私は角度のビューの1つにこれを組み込みたいと思いますが、jgery関数でngルートを使用することはできません。 jqueryは "#"ルーティングを認識しないので、プログラムは実行されますがタイムアウトします。私はビュー(main.html)の元のリンクを置く場合、これはページに私を連れて行くが、アプリケーションから終了します。私はちょうどポップアップが欲しいのでiframeを設定しようとしましたが、httpエラー要求を受け取ります。リダイレクトページのタイムアウトリクエストが別の角度表示にルーティングできません

セッションの期限切れ警告

あなたはしばらくの間、非アクティブにしてきました。セッションを延長するには、[続行]をクリックします。

セッションは120秒で有効期限が切れます。

は角度でjqueryの混合

  </div> 
     </div> 
    </div> 
</div> 
<div class="modal fade" id="mdlLoggedOut" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <h4 class="modal-title">You have been automatically signed out</h4> 
      </div> 
      <div class="modal-body"> 
       <p>Your session has expired.</p> 
      </div> 
      <div class="modal-footer"> 
      </div> 
     </div> 
    </div> 
</div> 
<script> 
    (function ($) { 
     var 
      session = { 
       //Logout Settings 
       inactiveTimeout: 10000,  //(ms) The time until we display a warning message 
       warningTimeout: 10000,  //(ms) The time until we log them out 
       minWarning: 5000,   //(ms) If they come back to page (on mobile), The minumum amount, before we just log them out 
       warningStart: null,   //Date time the warning was started 
       warningTimer: null,   //Timer running every second to countdown to logout 
       logout: function() {  //Logout function once warningTimeout has expired 
        //window.location = settings.autologout.logouturl; 

        $(location).attr('href', 'main.html') 
       }, 

       //Keepalive Settings 
       keepaliveTimer: null, 
       keepaliveUrl: "", 
       keepaliveInterval: 5000,  //(ms) the interval to call said url 
       keepAlive: function() { 
        $.ajax({ url: session.keepaliveUrl }); 
       } 
      } 
     ; 


     $(document).on("idle.idleTimer", function (event, elem, obj) { 
      //Get time when user was last active 
      var 
       diff = (+new Date()) - obj.lastActive - obj.timeout, 
       warning = (+new Date()) - diff 
      ; 

      //On mobile js is paused, so see if this was triggered while we were sleeping 
      if (diff >= session.warningTimeout || warning <= session.minWarning) { 
       window.location.replace("#"); 
      } else { 
       //Show dialog, and note the time 
       $('#sessionSecondsRemaining').html(Math.round((session.warningTimeout - diff)/1000)); 
       $("#timeout").modal("show"); 
       session.warningStart = (+new Date()) - diff; 

       //Update counter downer every second 
       session.warningTimer = setInterval(function() { 
        var remaining = Math.round((session.warningTimeout/1000) - (((+new Date()) - session.warningStart)/1000)); 
        if (remaining >= 0) { 
         $('#sessionSecondsRemaining').html(remaining); 
        } else { 
         session.logout(); 
        } 
       }, 1000) 
      } 
     }); 

     // create a timer to keep server session alive, independent of idle timer 
     session.keepaliveTimer = setInterval(function() { 
      session.keepAlive(); 
     }, session.keepaliveInterval); 

     //User clicked ok to extend session 
     $("#extendSession").click(function() { 
      clearTimeout(session.warningTimer); 
     }); 
     //User clicked logout 
     $("#logoutSession").click(function() { 
      session.logout(); 
     }); 

     //Set up the timer, if inactive for 10 seconds log them out 
     $(document).idleTimer(session.inactiveTimeout); 
    })(jQuery); 
</script> 

答えて

0

を続行良いアイデアではありません。あなたが一定期間後にリダイレクトを実現したい場合は、

var timeoutperiod; 
var redirect = function (url){ 
    $window.location.href = url; 
}; 

if (timeoutperiod) { 
     clearTimeout(timeoutperiod); 
    } 
timeoutperiod = setTimeout(redirect('url'), 5000); 

以下の方法でこれを達成することができ、あなたのコントローラに$ウィンドウを注入することを確認してください。

+0

実際のurlはtimeoutperiod = setTimeout(redirect( 'url')、5000)で定義されています。正しい? – woods

+0

はい正しい@woods –

関連する問題