Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

setInterval on body

Posted on 2006-05-22
2
Medium Priority
?
739 Views
Last Modified: 2010-08-05
here is the script i have, it works (counts down and all) but when it reaches the end, it does not redirect, but i can see it trying to do something every second. i have a feeling the setInterval is too quick and not letting it finish the document.location... any ideas?

<script language="JavaScript">
body.onload = function(){
setInterval("slideShow()", 1000);
}
function slideShow(){
reloadTime = document.getElementById('reloadTime');
      if(reloadTime.value == 1){
            document.location = 'page.php';
       } else {
            reloadTime.value = (reloadTime.value - 1);
      }                                                                  
}
0
Comment
Question by:qwertq
2 Comments
 
LVL 12

Accepted Solution

by:
_Maddog_ earned 400 total points
ID: 16738109
Hi qwertq,

Use clearInterval...

<script language="JavaScript">
var tempVar;
body.onload = function(){
tempVar = setInterval("slideShow()", 1000);
}
function slideShow(){
reloadTime = document.getElementById('reloadTime');
     if(reloadTime.value == 1){
          document.location = 'page.php';
          clearInterval(tempVar);
       } else {
          reloadTime.value = (reloadTime.value - 1);
     }                                                      
}
</script>

I personally don't like setInterval and use setTimeout most of the time.

- Maddog
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16738131
<script language="JavaScript">
body.onload = function(){
setInterval("slideShow()", 1000);
}
function slideShow(){

// Do not load, if not done.

if (window.status != window.defaultStatus) { return; }

reloadTime = document.getElementById('reloadTime');
     if(reloadTime.value == 1){
          document.location = 'page.php';
       } else {
          reloadTime.value = (reloadTime.value - 1);
     }                                                      
}
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question