Instead of using a plugin with unnecessary Kbytes, all you need is a simple function like this
(see explanation in comments):
<script>
(function() {
const idleDurationSecs = 60; // X number of seconds
const redirectUrl = '/logout'; // Redirect idle users to this URL
let idleTimeout; // variable to hold the timeout, do not modify
const resetIdleTimeout = function() {
// Clears the existing timeout
if(idleTimeout) clearTimeout(idleTimeout);
// Set a new idle timeout to load the redirectUrl after idleDurationSecs
idleTimeout = setTimeout(() => location.href = redirectUrl, idleDurationSecs * 1000);
};
// Init on page load
resetIdleTimeout();
// Reset the idle timeout on any of the events listed below
['click', 'touchstart', 'mousemove'].forEach(evt =>
document.addEventListener(evt, resetIdleTimeout, false)
);
})();
</script>
If you want to redirect to the home page (usually at /
), change '/logout'
to '/'
:
const redirectUrl = '/'; // Redirect idle users to the root directory
If you want to reload/refresh the current page, simply change '/logout'
in the code above to location.href
:
const redirectUrl = location.href; // Redirect idle users to the same page