Web page time-out auto-exit method

Source: Internet
Author: User
Tags setinterval

Ideas:
Use the Mousemover event to monitor whether there is a user Action page, write a timer interval for a specific time to detect if the page is not operating for a long time, and if so, exit;
The specific time code is as follows (JS):
var lasttime = new Date (). GetTime ();
var currenttime = new Date (). GetTime ();
var timeOut = 10 * 60 * 1000; Set timeout time: 10 minutes
$ (document). Ready (function () {
/* Mouse Move Event */
$ (document). MouseMove (function () {
Lasttime = new Date (). GetTime (); Update operation time

});
});

function Testtime () {
CurrentTime = new Date (). GetTime (); Update Current time
if (Currenttime-lasttime > Timeout) {//Determine if timeout
Console.log ("timeout");
}
}

/* Timer interval 1 seconds detect if the page is not operating for a long time */
Window.setinterval (testtime, 1000);

If you do not use JQ can be modified to the corresponding JS

var lasttime = new Date (). GetTime ();
var currenttime = new Date (). GetTime ();
var timeOut = 10 * 60 * 1000; Set timeout time: 10 minutes

Window.onload=function Init () {
Window.document.onmousemove= (function () {
Lasttime = new Date (). GetTime (); Update operation time
}
)};

function Testtime () {
CurrentTime = new Date (). GetTime (); Update Current time
if (Currenttime-lasttime > Timeout) {//Determine if timeout
Console.log ("timeout");
}
}

/* Timer interval 1 seconds detect if the page is not operating for a long time */
Window.setinterval (testtime, 1000);

Web page time-out auto-exit method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.