Wednesday 6 May 2015

SharePoint Idle timeout for windows user.

Recently i was working on sign out idle user after certain minutes. After so much tiresome tries i was able to generate a JavaScript that log out windows authenticated user in each browser.

Here is the code that you need to add in master page.

var IDLE_TIMEOUT = 30*60; //seconds - need to sign out if idle for 30 min.
        var _idleSecondsCounter = 0;
        document.onclick = function () {
            _idleSecondsCounter = 0;
        };
        document.onmousemove = function () {
            _idleSecondsCounter = 0;
        };
        document.onkeypress = function () {
            _idleSecondsCounter = 0;
        };
        window.setInterval(CheckIdleTime, 1000);//milliseconds (1 sec = 1000 millisecond) check every 1 second for idle timeout

        function CheckIdleTime() {
            _idleSecondsCounter++;
           
            if (_idleSecondsCounter >= IDLE_TIMEOUT) {
                document.location.href = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + "/_layouts/15/closeConnection.aspx?loginasanotheruser=true?Source=";
            }
        }

No comments:

Post a Comment