java - page not redirecting after session expires -
i have done simple page move page when session expires. have set time 50 seconds , after move page unfortunately not moving , helpless know wrong. grateful if please solve problem
function x(){ var timeout =<%=session.getattribute("login")%>; var checktimeout; checktimeout = function(){ if(timeout==null || timeout==""){ window.location.replace("failedsession.jsp"); //document.getelementbyid("b").innerhtml="session timed out"; // redirect timeout page }else{ window.settimeout(checktimeout, 1000); // check once per second }} checktimeout(); // insert checktimeout function when call x(), execute in end. }
the problem code:
nowhere in code, calling checktimeout();. why not being executed. should have checked execution of function putting alert inside function. during body onload @rgeorge has suggested.
note: logic looks alright. have habit of putting semicolons after javascript statements @mark has suggested.
answer updated:
1) don't use function name , variable name same. ex: x. have names unique. conflicting.
2) x greater lastactivity + timeout because x not increasing (7 > 1+1). means else condition never execute. means checktimeout never called.
3) function checktimeout() never execute because never called anywhere. executing x(). not sufficient call checktimeout().
answer updated:
do this:
<script type="text/javascript"> function x(){ var timeout =1; var lastactivity = 1; var x=7; var checktimeout; checktimeout = function(){ if(x > lastactivity + timeout){ document.getelementbyid("b").innerhtml=x; // redirect timeout page }else{ window.settimeout(checktimeout, 1000); // check once per second }} checktimeout(); // insert checktimeout function when call x(), execute in end. } </script> your code works fine me. div value changes 7. , code >> http://jsfiddle.net/hmhp9/
Comments
Post a Comment