-1

ユーザーが画面ページで何らかのアクティビティを実行しているかどうかを自動的にチェックできるスクリプトを作成したいと考えています。1 分間アクティビティが受信されない場合は、アイドル状態の理由を尋ねて彼に警告したいと思います。これはjquery/javascriptとphpでできると思います。私の夢を実現できるように、誰かが私に何かを与えてくれませんか。

また、アイテムをクリックしないと、合計 1 分後に自動ログアウトされます。

4

3 に答える 3

3
  • ユーザーアクティビティを示す変数を設定します。最初はfalseです。
  • 現在の時刻を示す変数を設定します
  • ドキュメントワイドクリックハンドラーを設定して、ユーザーがページ内の任意の場所をクリックしたときにユーザーアクティビティをtrueに設定します
  • を使用してリスナー関数を設定し、setTimeout過去の時間と最初の変数を確認します。真の場合はリスニングをキャンセルします。それ以外の場合は、過去の時間が1分未満の場合はリスニングを続行し、過去の時間が1分を超える場合はユーザーに警告してアクションを実行します

このアルゴリズムのq&dの例については、このjsfiddleを参照してください。

幸運を!

于 2012-05-04T06:58:00.563 に答える
2

アイドルプラグイン

このプラグインはトリックを行います

<!-- dialog window markup -->
<div id="dialog" title="Your session is about to expire!">
   <p>You will be logged off in <span id="dialog-countdown"></span> seconds.</p>
   <p>Do you want to continue your session?</p>
</div>



// setup the dialog
$("#dialog").dialog({
 autoOpen: false,
 modal: true,
 width: 400,
 height: 200,
 closeOnEscape: false,
 draggable: false,
 resizable: false,
 buttons: {
    'Yes, Keep Working': function(){
        // Just close the dialog. We pass a reference to this
        // button during the init of the script, so it'll automatically
        // resume once clicked
        $(this).dialog('close');
    },
    'No, Logoff': function(){
        // fire whatever the configured onTimeout callback is.
        $.idleTimeout.options.onTimeout.call(this);
    }
 }
});

// start the plugin
$.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
idleAfter: 300, // user is considered idle after 5 minutes of no movement
pollingInterval: 60, // a request to keepalive.php (below) will be sent to the server every minute
keepAliveURL: 'keepalive.php',
serverResponseEquals: 'OK', // the response from keepalive.php must equal the text "OK"
onTimeout: function(){

    // redirect the user when they timeout.
    window.location = "timeout.htm";

},
onIdle: function(){

    // show the dialog when the user idles
    $(this).dialog("open");

},
onCountdown: function(counter){

    // update the counter span inside the dialog during each second of the countdown
    $("#dialog-countdown").html(counter);

},
onResume: function(){

    // the dialog is closed by a button in the dialog
    // no need to do anything else

}
});

ajaxを使用すると、サーバーにリクエストを送信してセッションを閉じることができます

于 2012-05-04T06:55:26.197 に答える
2

ユーザーが非アクティブであるかどうかを判断するには、bodyタグにさまざまなイベントハンドラーを追加する必要があります。onmousemove、oncllick、onkeypressのイベントで十分だと思います。

  • タイマーを開始し、特定の時間になると、ログアウトURLにアクセスする必要があります
  • 前述のイベントハンドラーを実装します。それらの中でタイマーをリセットします。

これで十分です。

于 2012-05-04T06:56:13.010 に答える