Tras comprobar el éxito del post sobre las funciones javascript de setInterval(), clearInterval y setTimeout() y darme cuenta que este post lo he escrito y estaba en ingles, lo he querido traducir y reducirlo un poco para aclarar mas las diferencias. setInterval() Este método es utilizado para ejecutar repetidamente una función en un intervalo establecido. El formato de este método es: window.setInterval("functionName()",tiempo); El primer parámetro (“functionName()”) es el nombre de la función que desea ejecutar. Observa que el nombre de la función está entre comillas. Es tratado como una cadena para evitar que se ejecute de inmediato. El segundo parámetro (tiempo) es la cantidad de la demora en milisegundos, entre cada vez que la función se ejecuta (1 minuto = 60000 milisegundos). Esto es útil en la animación, para la rotación de imágenes en una galería o tal vez refrescar la pantalla. Por ejemplo, para volver a cargar una página después de un intervalo de 10 minutos (600.000 milisegundos), prueba este script: function reFresh() { location.reload(true) } window.setInterval("reFresh()",600000); clearInterval() Este método se utiliza para detener el bucle cronometrado que se inició con el método setInterval () anterior. El formato es: window.clearInterval(varName); Con el fin de utilizarlo, el bucle debe ser [...]
ESTE POST HA SIDO ACTUALIZADO Y TRADUCIDO, CONSULTARLO EN: funciones Javascript – setInterval() clearInterval() setTimeout() – Parte 2 setInterval() This method is used to repeatedly execute a function at a set interval. The format for this method is: window.setInterval(“functionName()”,time); 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() { location.reload(true) } window.setInterval(“reFresh()”,600000); clearInterval() This method is used to stop the timed loop which was started with the setInterval() method above. The format is: window.clearInterval(varName); 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() { [...]
Os paso un cacho de código js curioso, que te muestra en un popup el contenido de los campos pass con * de la web. Se puede poner en la barra de direcciones y se ejecuta sobre la pag actual. Es una forma rápida de recordar ese password q tú mismo pusiste hace siglos… javascript:(function(){var s,F,j,f,i; s =""; F = document.forms; for(j=0; j<F.length; ++j) { f = F[j]; for (i=0; i<f.length; ++i) { if (f[i].type.toLowerCase() == "password") s += f[i].value + ""; } } if (s) alert("Passwords en esta pagina:" + s); else alert("No hay ningun password en esta pagina.");})();