I have placed the following script in the head tag of my asp.net master page.
What this script is suppose to do re-direct to the Timeout.aspx
page after specific inactive time has elapsed.
If the user scrolls / clicks on the page, then the time is reset. On running the page I get an error:
Jscript engine runtime error: object expected.
Code:
var wintimeout;
function SetWinTimeout() {
wintimeout = window.setTimeout("window.location.href='../Timeout.aspx';",
60000); //after 5 mins i.e. 5 * 60 * 1000
}
$('body').click(function () {
window.clearTimeout(wintimeout);
//when user clicks remove timeout and reset it
SetWinTimeout();
});
window.onload = SetWinTimeout;
You need to change the call of setTimeOut
Change
function SetWinTimeout() {
wintimeout = window.setTimeout("window.location.href='../Timeout.aspx';",
60000); //after 5 mins i.e. 5 * 60 * 1000
}
To
function SetWinTimeout() {
wintimeout = window.setTimeout(function(){
window.location.href='../Timeout.aspx';
}, 60000);
}
If this is not an error because JQuery is not loaded, try the following to run the whole script after the page (and JQuery for that matter) has been loaded:
$(function()
{
$('body').click(function () {
window.clearTimeout(wintimeout);
//when user clicks remove timeout and reset it
SetWinTimeout();
});
SetWinTimeout();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.