Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Need your suggestion

Hello,

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??

Thanks
0
usmbay
Asked:
usmbay
  • 3
  • 2
  • 2
  • +1
1 Solution
 
12_CenturiesCommented:
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 {
    window.location.replace(window.location.href);
  }
}

// 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)
    clearTimeout(reloadTimer);
  document.form1.reloadTime.value = 'Disabled';
}
//-->
</script>


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

 <meta http-equiv="refresh" content="600;url=http://www.yoursite.com/yourhomepage.html" />

Change 600 to the number of seconds you desire.
0
 
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)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
glcumminsCommented:
Yes, you are correct. If the user is still reading the page after the time period has expired, he will still be redirected.
0
 
12_CenturiesCommented:
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(){
   window.location="http://www.yourdomain.com/";
}
var tid, time, action;
function setInactivityTimer (time, action, repeat) {
  window.time = time;
  window.action = action;
  window.repeat = repeat;
  if (tid)
    clearTimeout(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 + ');';
  else
    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.
0
 
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 ??
0
 
GawaiCommented:
how about this one ?
<body onload="setTimeout('window.location.href = \'home.aspx\'', 20 * 60 * 1000);">

20 min is the timeout delay
0
 
glcumminsCommented:
>> 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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now