Useful Resources
syllabus | schedule | exercises | assignments | class notes | resources | students | ARTC courses
Timeouts

Description:

A "timeout" is like setting a kitchen timer and telling it to do something specific when it's time runs out.

The Code:

<head>
      <script type="text/javascript">
            function delayedAlert() {
                  setTimeout('alert("TESTING")', 3000);
            }
      </script>
</head>

<body>
      <a href="#" onmouseup="delayedAlert();">Delayed Alert on Mouse Up (click)</a>
</body>


Explanation:

The mouseup event calls the "delayedAlert" function and this starts the javascript timeout with "setTimeout", and passes two variables - the first is what you'd like to run, and the second is time (in milliseconds) before it should run.

In this case, we have it call an alert (with "TESTING" as it's alert text), and we tell it to wait 3 seconds (3000 milliseconds) before it calls it.

[BACK to RESOURCES]