Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:37:26+00:00 2026-05-28T17:37:26+00:00

I believe this has been asked before but no concrete answer has been determined.

  • 0

I believe this has been asked before but no concrete answer has been determined.

On my website http://euphoricsoftware.com/ there is a fancy countdown script to automatically take you to the normal site, as opposed to mobile or low bandwidth. The script works in every browser with <body onload="setTimeout(countDown(8),1000);"> (where 8 is the number to start from) except sometimes in Chrome the countdown doesn’t move and opening the JS console reveals Uncaught ReferenceError: countDown is not defined.

Also on the page is a button which lets you pause and resume the countdown. Resuming calls the countDown() function, too, and even when the undefined error happens onload, if you click the button twice the countdown will work, so it seems to be something to do with onload.

Here’s the code I’ve been using (SO’s code format has stuffed up the spacing a bit):

<html>
<head>
    <!-- ... -->
    <script type="text/javascript">
    var stopRedirect = false;
    var back = 0;

    function redirect()
    {
        if (!stopRedirect) {window.location = "home.html";}
    }
    function countDown(num)
    {
        if (!stopRedirect)
        {
            back = num-1;
            if (num < 10)
            {
                document.getElementById("top").innerHTML=num+1;
            }
            document.getElementById("middle").innerHTML=num;
            if (num > 1)
            {
                document.getElementById("bottom").innerHTML=num-1;
                var t = setTimeout("countDown("+(num-1)+")",1000);
            }
            else
            {
                document.getElementById("bottom").innerHTML="&nbsp;";
                document.getElementById("unit").innerHTML=" second&nbsp;";
                var r = setTimeout("redirect()",1000);
            }
        }
    }

    function stop()
    {
        if (!stopRedirect)
        {
            stopRedirect = true;
            document.getElementById("stop").style.display="none";
            document.getElementById("start").style.display="block";
        }
    }
    function start()
    {
        if (stopRedirect)
        {
            stopRedirect = false;
            document.getElementById("stop").style.display="block";
            document.getElementById("start").style.display="none";
            var c = setTimeout("countDown("+(back)+")",1000);
        }
    }
</script>
</head>
<body onLoad="setTimeout(countDown(8),1000);">
    <!-- ... -->

and you can see the site in action at http://euphoricsoftware.com/
Does anyone know why this is happening? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:37:27+00:00Added an answer on May 28, 2026 at 5:37 pm

    I’m not quite sure why you get that error, given that your function is defined in the <head> and you don’t try to use it until the onload of the body, but your code does have a problem. This part from your onload="":

    setTimeout(countDown(8),1000);
    

    will, when the onload occurs and the code is run, call the countDown() function immediately, passing a parameter of 8, and then take whatever that function returns and pass it to setTimeout() to be executed in 1 second’s time. In your case your function doesn’t return a particular value, so in effect you are passing undefined to setTimeout().

    What you want to do is pass setTimeout() either a function reference or a string.

    You can’t pass a reference to countDown() directly at the same time as passing a parameter for that function (at least, not with a syntax of setTimeout() that will work in IE), so you would need to wrap it in an anonymous function like this:

    onload="setTimeout(function() { countDown(8); }, 1000);"
    

    Or you can use the string format similar to within your countDown() function body (using single-quotes since the onload attribute currently uses doubles):

    onload="setTimeout('countDown(8);', 1000)"
    

    Note that the string format is generally frowned upon because it is slower and affects the scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe this question has been asked before. I tried looking for it but
(Apologies if this has been asked before - I can't believe it hasn't, but
I apologize if this has been asked before, but I believe that for me,
I believe this questions has been asked in some or the other way but
I see that this question has been asked before but the context around the
You're probably thinking this has been asked a million times before but I think
I'm pretty sure this has been asked before, but I can't for the life
I am sure this has been asked before, but I have yet to find
I know this has been asked here before but my conditions are a little
I find it hard to believe this hasn't been asked before, but it doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.