ユーザーが画面ページで何らかのアクティビティを実行しているかどうかを自動的にチェックできるスクリプトを作成したいと考えています。1 分間アクティビティが受信されない場合は、アイドル状態の理由を尋ねて彼に警告したいと思います。これはjquery/javascriptとphpでできると思います。私の夢を実現できるように、誰かが私に何かを与えてくれませんか。
また、アイテムをクリックしないと、合計 1 分後に自動ログアウトされます。
ユーザーが画面ページで何らかのアクティビティを実行しているかどうかを自動的にチェックできるスクリプトを作成したいと考えています。1 分間アクティビティが受信されない場合は、アイドル状態の理由を尋ねて彼に警告したいと思います。これはjquery/javascriptとphpでできると思います。私の夢を実現できるように、誰かが私に何かを与えてくれませんか。
また、アイテムをクリックしないと、合計 1 分後に自動ログアウトされます。
setTimeout
過去の時間と最初の変数を確認します。真の場合はリスニングをキャンセルします。それ以外の場合は、過去の時間が1分未満の場合はリスニングを続行し、過去の時間が1分を超える場合はユーザーに警告してアクションを実行しますこのアルゴリズムのq&dの例については、このjsfiddleを参照してください。
幸運を!
このプラグインはトリックを行います
<!-- 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を使用すると、サーバーにリクエストを送信してセッションを閉じることができます
ユーザーが非アクティブであるかどうかを判断するには、bodyタグにさまざまなイベントハンドラーを追加する必要があります。onmousemove、oncllick、onkeypressのイベントで十分だと思います。
これで十分です。