You need to sign in to do that
Don't have an account?
Redirect user after inactivity
Hi All
I am currently trying to create a sites page that redirects the user after a certain amount of inactivity, and I was wondering if anyone found a good way of doing this?
I tried using a class that would be activated when the user clicks on the form then waits until it sends back the pageReference, but the problem is it wouldn't reset when the user clicked the form again.
I then turned to javascript, creating a simple function that resets a timer, then waits before redirecting. The problem is the form contains outputPanels that render dynamically (all contained in the 1 form tag), and while the javascript works fine for the first visible panel, when the second is rendered, it stops reseting the first timer when the form is clicked on.
Small example of the code used:
<apex:page>
<script>
var timerId =0;
function tojs() {
clearTimeout(timerId);
timerId = setTimeout('redirect()',10000);
//set to 10 seconds for testing
}
function redirect() {
location.href = '../apex/FormTimeOut';
}
</script>
<apex:form id="frm" onclick="tojs()">
<apex:outputPanel rendered="{!render1}">
<apex:inputCheckbox value="{!render2}">
<apex:actionSupport event="onchange" action="{!render2ndPanel}" rerender="frm"/>
</apex:inputCheckbox>
</apex:outputPanel>
<apex:outputPanel rendered="{!render2}">
tra la la la
</apex:outputPanel>
</apex:form>
</apex:page>
So with this example the function tojs() would work as normal when the first outputPanel is clicked on (i.e. resetting the timer), but when the checkbox is ticked and the 2nd panel is rendered the tojs() timer is no longer reset. Could this be due to rerender?
Has anyone come up with a good way of doing this?
Thanks!
public Datetime tTime {get;set;}
public PageReference toTest() {
Datetime cTime = Datetime.now();
if (cTime > tTime.addMinutes(20)) {
if (Edit == true) {
List<Database.DeleteResult> ddr = Database.Delete(editApps,false);
}
PageReference test = new PageReference('/apex/appFormTimeOut');
test.setRedirect(true);
return test;
} else {
tTime = cTime;
return null;
}
}
where tTime is set as the current time on the page render. This works for the entire form, however the redirect only occurs when the user clicks on the form after 20 mins of activity, rather than instantly redirecting after the inactivity.
Does anyone know if there is a way I could implement a wait() functionality in apex?
Thanks