Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hai
I need timer in asp.net using java script. My need is i have pop up alert message in java script when page is idle for 2 mins,if page is redirected timer is start after idle for 2 mins automatically pop up the message box without any click event, using only timer.

Note: i use master page and every page is redirected the timer start and when reach 2 mins idle it open message box automatically.
Posted
Comments
Sergey Alexandrovich Kryukov 30-May-13 23:33pm    
There is no such think as "Java script". Java is not a scripting language. :-)
—SA
Aravindba 31-May-13 1:09am    
Then how to refresh page automatically every 3 mins ?,u can see that in online cricket score page,it automatically refresh page and update score,like these how to get ?
Sergey Alexandrovich Kryukov 31-May-13 1:20am    
How it's "then"? :-)
—SA
Sergey Alexandrovich Kryukov 31-May-13 1:20am    
Why wouldn't you simply read about it?
—SA

 
Share this answer
 
Comments
Aravindba 31-May-13 2:19am    
ok thank u for u reply ,this one how implement in web page,i mean if page load timer is start,if same page is idle for 3 mins message box is pop up,but in between 3 mins if user click any place of page the timer is again to restart,
note i am use master page also,is it possible simply write java-script code in master page only ?
Sergey Alexandrovich Kryukov 31-May-13 2:21am    
What's the difference? Actually, read the article with attention, you will see how to use it.
—SA
Aravindba 31-May-13 2:47am    
the above code is execute when button is clicked,i want if page is open at the time the timer is start,if page is busy the timer again and again restart so message box not appear,if idle for 3 sec need to appear msg box.

Here i attach some code pls modify with ur code to pop up msg box automatically

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
if(logoutUser){
alert("You Session Expired");
window.location.href = "Logout.aspx";
}
else{
ResetLogOutTimer();
}
}
function OnTimeoutReached(){
logoutUser = true;
}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="tbxarea" runat="server" title="Write your name here">
</div>
</form>

<script>document.body.onclick = onuser_activite;
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
</script>
</body>
</html>

the above code is work when i click text box,but i want without click text box or any place of the page just pop up message box
Sergey Alexandrovich Kryukov 31-May-13 8:17am    
If course you can do it without the click. What's the problem?
—SA
Aravindba 2-Jun-13 11:49am    
the posted code works when i click page,it does not open alert message automatically when page is idle for 3 secs,this is my problem,just u paste this code and wait for 3 secs it does not work,if u click page then only it open alert message box,just try it and solve me,i use master page also,so where i put this code ? in every page or only master page is enough,if i put code in master page then i click child page(ie.other than master page place(i use menu bar in master page ))other than menu bar it will work ?
Add below mention JavaScript just before closing body tag(</body>) in your Master page

<script>
    
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){     
    if(logoutUser){
;
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true; 
    alert("You Session Expired");
    window.location.href = "Logout.aspx";

}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}

    
    document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900