funciones Javascript – setInterval() clearInterval() setTimeout()

funciones Javascript – setInterval() clearInterval() setTimeout() – Parte 2


This method is used to repeatedly execute a function at a set interval. The format for this method is:


The first parameter (“functionName()”) is the name of the function that you want to have executed. Notice that the function name is in quotes. It’s treated as a string to prevent it from executing immediately. The second parameter (time) is the amount of the delay in milliseconds, between each time the function is executed (1 minute = 60000 milliseconds). This is useful in animation, for rotating pictures in a gallery or perhaps refreshing the screen. For instance, to reload a page after an interval of 10 minutes (600,000 milliseconds), try this script:

function reFresh() {





This method is used to stop the timed loop which was started with the setInterval() method above. The format is:


In order to use it, the loop must be assigned to a variable.

Let’s go back to our page refresh script above. We only need to add the var reserved word in front of the setInterval() loop:

function reFresh() {


var repeat=window.setInterval("reFresh()",600000);

Then we could create a button to stop the page refresh:


  // The next two lines should all be on one line

  <input type="Button" value="Stop the Page Refresh"



The function is the same as we created previously except, as I noted, the setInterval method has now been assigned to a variable. The button we created merely says to clear the time interval of the variable repeat. If you want to see this script in action at a faster pace, change the time interval from 600000 (10 minutes) to 60000 (1 minute). Once you load the page, go back and edit the page, adding something to it, and save it. Then, go back to the browser and wait for it to refresh.


This method is used to execute a JavaScript function after a predetermined amount of time. (The name is a bit misleading. It doesn’t stop the script for a period of time; it waits a period of time before beginning.) Unlike the setInterval() method, it only executes once. You will remember we used this when we looked at the blur() and focus() methods. It was used to give the IE browser time to catch up before we printed data to the new window. The format is:


This method has many different applications. It could be used in a game, to set a specified amount of time for performing a procedure, to reset a page when the computer is set up in a kiosk environment or it could be used to popup a window for a friendly reminder to a visitor. There are many other applications. The trick is not to annoy your visitors. Let’s take a look at how this methods works:

function inquire() {

  alert("Are you still there?");


var ask=window.setTimeout("inquire()",10000);


This method is used for clearing the time interval set by the setTimeout() method. It works along the same lines as the clearInterval. Using our script above, let’s see how it works. First, here’s our setTimeout script:

function inquire() {

  alert("Are you still there?");


var ask=window.setTimeout("inquire()",10000);

Next, we add a button to our page to cancel the alert window in the inquire function:


  // The next two lines should all be on one line

  <input type="Button" value="Stop the Alert Window"



This button can be used to stop the action that will be executed by the setTimeout method.


That wraps up of look at the methods associated with the window object. In the next installment we will take a look at some of the event handlers and see how we can use them.


Tags de búsquedas:

js setinterval stop,javascript setinterval stop,js settimeout clear,js set interval,settimeout javascript interval,window setinterval( refresh() 60000),javascript clear settimeout,getinteval javascript,setinterval javascript sop refresh,setinterval js stop,setInterval settimeout javascript javascript setTimeout javascript clearInterval javascript setinterval clear javascript seTinterval clearInterval setInterval clearInterval javascript javascript clear setInterval stop setinterval javascript window setInte,setinterval stop,settimeout javascript dentro de un bucle,clearInterval this,settimeout with clearinterval

Noticias relacionadas »

2 comentarios en funciones Javascript – setInterval() clearInterval() setTimeout()

  1. joseba
    / Responder

    Cómo puedo medir cuánto tarda una función en ejecutarse??

  2. Pingback: funciones Javascript – setInterval() clearInterval() setTimeout() – 2 | Pedro Ventura

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Invertir en criptomonedas: »


Cómo comprar bitcoin

Invertir y comprar Bitcoin y otras altcoins es más fácil de lo que crees.

1) Si sólo quieres comprar Bitcoin, Ethereum o Litecoin como inversión, tu opción es Coinbase

2) Si quieres probar con otras criptomonedas tu opción es Binance

3) Cualquier duda escríbeme con total libertad al formulario de contacto para resolver dudas:

¡Comparte este artículo! »

  • Margherita (5 horas)
    Hola, tengo un problema con el plugin. Tanto en la…
  • Pablo H (2 semanas)
    Hola Pedro, Muchas gracias por el post, me fue muy…
  • Pedro Ventura (2 semanas)
    Hola Margat Muchísimas gracias por tu comentario, me alegro de…
  • Pedro Ventura (2 semanas)
    Hola Rebeca, Tan sólo se permite 1 dominio por cuenta.…
  • Rebeca (2 semanas)
    Hola. Yo ya tengo un dominio en bitly pero quiero…
  • Pedro Ventura (3 semanas)
    Hola Raul, 1. No habría problema, de hecho yo sigo…

Suscríbete al newsletter »

Proporciona tu correo electrónico a continuación y recibe las últimas noticias! Funciona con Feedburner de Google

Archivo »

Leer entrada anterior
Revelar las contraseñas con Javascript

Interesante manera para obtener las contraseñas de un formulario con este simple fragmento de código javascript, que te muestra en...