viernes, marzo 20, 2009

Relog XUL

Para crear un relog en XUL es muy sencillo.

Creas tu XUL:

xmlns ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title = "Reloj"
sizemode = "maximized"
onunload="window.setInterval('contador_reloj()',1000);">

'function agregarceros(cantidad,cuantos_ceros){
' cantidad += "";
'
' for(i=cantidad.length;i'
' cantidad = "0"+cantidad;
'
' }
'
' return cantidad;
'
'}
'
'function contador_reloj(){
' try{
' momentoActual = new Date();
' hora = momentoActual.getHours();
' minuto = momentoActual.getMinutes();
' segundo = momentoActual.getSeconds();
' horaImprimible = agregarceros(hora,2) + ":" + agregarceros(minuto,2) + ":" + 'agregarceros(segundo,2);
' //alert(horaImprimible);
' document.getElementById("reloj").value = horaImprimible ;
' }catch(e){
' alert(e);
' }
'}




La funcion que hace la magia del timer es window.setInterval su aquivalente setTimeout en desarrollo web.

funciona de la misma manera xD.


Espero que les sirva