Developer Checklist — JavaScript Appendices

Correct code

JS_C_A5: Warn the user when a time-limit is about to expire, and provide a mechanism for extending it

This example shows a very simple timed process, which produces a confirm dialog when its time has elapsed, then re-starts the timer only if the user presses OK. This allows for arbitrary extensions to timed activity.

In practise, this process would be linked to something more practical. For example, the timer function could use Ajax to call a server-side script, which tells you how much time your session has to live; then the confirmation response could call another server-side script, that either resets the session time-to-live, or loads a new page. The timing of such a process would also be much slower, perhaps every 10–15 minutes, instead of the 10-second timeout that's used in this demo!

Time restrictions like this should be avoided wherever possible, but may be required in highly-sensitive environments, or for tests.

Live Demo

Wait a few seconds, until the confirm dialog appears ...

JavaScript Code

The JavaScript code for this example can be found in: JS_C_A5.js