Need your suggestion


I have a web application, I need to develope something like screen saver
the idea is if the user stay long time doing nothing in one of the pages , I want the application goes to the home page, do have an idea how I can do it??

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yes, use a timeout... Try this:

<script type="text/javascript" language="javascript">
// Declare a global variable and initialize to null.

var reloadTimer = null;

// This function gets called when the window has completely loaded.
// It starts the reload timer with a default time value.

window.onload = function()
  setReloadTime(600); // Pass a default value of 600 seconds (5 minutes).

// setReloadTime() does two different things:
// (1) If a value is passed as an argument, the function clears the current timer
//     (if its running) and starts the timer again with the new time
//     and saves a reference to the timer: reloadTimer.
// (2) If no argument is passed, the page is reloaded. The only time no argument
//     will be passed is when the 'setTimeout()' function times out and calls
//     this function.

function setReloadTime(secs)
  if (arguments.length == 1) {
    if (reloadTimer) clearTimeout(reloadTimer);
    reloadTimer = setTimeout("setReloadTime()", Math.ceil(parseFloat(secs) * 1000));
  else {

// disableReload() clears the current timer if its running, and since it will
// never timeout, setReloadTime() will not be called (with no args) and
// the page will not reload.

function disableReload()
  if (reloadTimer)
  document.form1.reloadTime.value = 'Disabled';

Hope this helps!
Here is a similar result, but with less code. In the head of the HTML document, put:

 <meta http-equiv="refresh" content="600;url=" />

Change 600 to the number of seconds you desire.
usmbayAuthor Commented:
but this will go to homepage either the user works in the current page or not it just switch to homepage after certain time (timeout)
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Yes, you are correct. If the user is still reading the page after the time period has expired, he will still be redirected.
Okay, sorry about that. Here's a different approach... if the use has not moved their mouse in the webpage, it will bump them back to the home page:

function post_action(){
var tid, time, action;
function setInactivityTimer (time, action, repeat) {
  window.time = time;
  window.action = action;
  window.repeat = repeat;
  if (tid)
  if (document.layers)
    document.captureEvents(Event.MOUSEMOVE | Event.KEYUP);
  document.onmousemove = document.onkeyup =
    function (evt) {
      setInactivityTimer(window.time, window.action, window.repeat);
      return true;
  if (repeat)
    action += '; setInactivityTimer('
              + time + ', "' + action + '", ' + repeat + ');';
    action += '; clearEvents();';
  tid = setTimeout(action, time);
function clearEvents() {
  if (document.layers)
    document.releaseEvents(Event.MOUSEMOVE | Event.KEYUP);
  document.onmousemove = document.onkeyup = null;
setInactivityTimer(2000, 'post_action();', true);  // 2000 is the time in milliseconds.

Let me know if this works for you.

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
usmbayAuthor Commented:
yes it works fine , it's requir to put the script in each page , I have about 15 page , is there other way ??
how about this one ?
<body onload="setTimeout('window.location.href = \'home.aspx\'', 20 * 60 * 1000);">

20 min is the timeout delay
>> put the script in each page

You can place the code in a seperate file, and then include it like this:

 <script type="text/javascript" language="Javascript" href="filename.js"></script>

where "filename.js" is the name of the file that contains the code.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.