Programación Y Desarrollo Web
:: 
 
Apache ASP C/C++ C++ Builder


CSS Delphi HTML Java


JavaScript MySQL PHP


SQL Server Visual C++ W3C  
 
 
 
.: Inicio  ::  Código  ::  Javascript :.
 
 
 
 
  Manuales
  Código
  Trucos Windows
  Descargas
  Vínculos
 
 
 
 

 
• Hora

A lo mejor es mucho código, pero es para que me aparezca un cero a la izquierda cuando en la hora o en los minutos, sean menor a 10

<!-- Copia el siguiente código dentro de la etiqueta <head> -->
<script language="JavaScript">
  var id
  function hora(){
    var D=new Date()
    var h=D.getHours()
    var m=D.getMinutes()
    var s=D.getSeconds()
    if(parseInt(h)==0 && parseInt(m)>10)
      document.f1.edit1.value="12"+" : "+"0"+m+" : "+s+" am"
    else if(parseInt(h)==0 && parseInt(m)>=10)
      document.f1.edit1.value="12"+" : "+m+" : "+s+" am"
    else if(parseInt(h)<10 && parseInt(m)<10)
      document.f1.edit1.value="0"+h+" : "+"0"+m+" : "+s+" am"
    else if(parseInt(h)<13 && parseInt(m)<10)
      document.f1.edit1.value="0"+h+" : "+"0"+m+" : "+s+" am"
    else if(parseInt(h)<13)
      document.f1.edit1.value=h+" : "+m+" : "+s+" am"
    else if(parseInt(h)==12 && parseInt(m)<10)
      document.f1.edit1.value=h+" : "+"0"+m+" : "+s+" pm"
    else if(parseInt(h)==12)
      document.f1.edit1.value=h+" : "+m+" : "+s+" pm"
    else if((parseInt(h)>12 && parseInt(h)<22) && parseInt(m)<10)
      document.f1.edit1.value="0"+(parseInt(h)-12)+" : "+"0"+m+" : "+s+" pm"
    else if(parseInt(h)>12 && parseInt(h)<22)
      document.f1.edit1.value="0"+(parseInt(h)-12)+" : "+m+" : "+s+" pm"
    else if(parseInt(h)>21 && parseInt(m)<10)
      document.f1.edit1.value=(parseInt(h)-12)+" : "+"0"+m+" : "+s+" pm"
    else if(parseInt(h)>21)
      document.f1.edit1.value=(parseInt(h)-12)+" : "+m+" : "+s+" pm"
    id=setTimeout("hora()",1000)
  }
  function parar(){
    clearTimeout(id);
  }
</script>

<!-- Copia el siguiente código dentro de la etiqueta <body> -->
<form name="f1">
  <input type=text name="edit1"><p>
  <input type=button name="boton" value="mostrar" onclick="hora()"><p>
  <input type=button name="boton2" value="detener" onclick="parar()">
</form>

Ver Ejemplo

 

 
• Fecha

<!-- Copia el siguiente código dentro de la etiqueta <head> -->
<script language="JavaScript">
  var D=new Date()
  var d=D.getDate()
  var m=D.getMonth()
  var a=D.getYear()
  function fecha(){
    document.f1.edit1.value=d+"/"+(parseInt(m)+1)+"/"+a
  }
</script>

<!-- Agrégale el siguiente evento: << onload="fecha()" >> a la etiqute <body> -->
<body onload="fecha()">

<!-- Copia el siguiente código dentro de la etiqueta <body> -->
  <form name="f1">
    <input type=text name="edit1">
  </form>

Ver Ejemplo

 

 
• Cronómetro

Dependiendo de la velocidad de la máquina, será la velocidad del cronómetro

<!-- Copia el siguiente código dentro de la etiqueta <head> -->
<script language="JavaScript">
  var id, m, s, ms
  function ini(){
    ms++
    if(ms==9){
      s++
      ms=0
    }
    if(s==60)
      m++
    document.f1.edit1.value = m+" : "+s+" : "+ms
    id = setTimeout("ini()", 100)
  }

  function parar(){
    clearTimeout(id)
  }

  function ceros(){
    m = 0
    s = 0
    ms = 0
    document.f1.edit1.value = "00 : 00 : 00"
  }
</script>

<!-- Agrégale el siguiente evento: << onload="ceros()" >> a la Etiqute <body> -->
  <body onload="ceros()">

<!-- Copia el siguiente código dentro de la Etiqueta <body> -->
  <form name="f1">
    <input type=text name="edit1" value="00 : 00 : 00"><p>
    <input type=button name="boton" value="   Iniciar   " onclick="ini()"><p>
    <input type=button name="boton2" value=" Detener " onclick="parar()"><p>
    <input type=button name="boton3" value="Reiniciar" onclick="parar(); ceros(); ">
  </form>

Ver Ejemplo

 

 
• Favoritos

<!-- Este código ponlo dentro de la etiqueta body -->
<a href="javascript:window.external.AddFavorite('http://www.tupagina.com','Nombre del Sitio')">Agregar a Favoritos</a>
Ejemplo: Agregar a Favoritos

<!--El siguiente código también te agrega a favoritos, solo que este, primero verifica tu navegador-->

<!--Copia el siguiente código dentro de la etiqueta <head>-->
<script language="JavaScript">
  function agregar(){
    if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.tusitio.com";
      var titulo="nombre del sitio";
      window.external.AddFavorite(url,titulo);
    }
    else {
      if (navigator.appName == "Netscape")
        alert ("presione crtl+d para agregar este sitio en sus bookmarks");
    }
  }
</script>

<!-- este código ponlo dentro de la etiqueta body -->
  <a href="#" onClick="javascript:agregar();">agregar a favoritos</a>

 

 
• Página de Inicio

<!-- Copia este código y pégalo dentro de la etiqueta <body> -->
<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('www.tupagina.com');return false">página de inicio</a>

Ejemplo: Establecer Como Página de Inicio

<!-- Solo para Internet Explorer -->

 

 
• Evitar Selección

El siguiente script, no permite que seleciones el texto y demás multimedia de tu página

<!-- El siguiente código, ponlo dentro de las etiquetas <head> -->
<script language="javascript">
  function seleccion(){
    window.event.returnValue = false
  }
  document.onselectstart = seleccion()
</script>

 

 
• Desactivar Tecla "PrintScreen"

<!-- El siguiente script, ponlo dentro de las etiquetas <head> -->
<script language="javascript">
function clp_clear(){
var content = window.clipboardData.getData("Text");
if (content==null){
window.clipboardData.clearData();
}
setTimeout("clp_clear()",1000);
}
</script>

<!-- Después agrega la función "clp_clear()" al evento onLoad del body -->
  <body onLoad="clp_clear()"">

 

 
• Desabilitar Botón Derecho del Mouse

<!-- El siguiente script, ponlo dentro de las etiquetas <head> -->
<script language="javascript">
  function click(){
    if(event.button==2){
      alert('botón desabilitado')
    }
  }
</script>

<!-- Después agrega la función "click()" al evento onLoad del body -->
  <body onLoad="click()">

 
 
 
[  Inicio  ¦  Mapa del Sitio  ¦  Contacto  ]
 
 
 
Página diseñada por: TSUI Jorge Alejandro Mendoza Torres.
Sitio optimizado para ie5+/Firefox 2.0; res 800 x 600.
 
Hosted by www.Geocities.ws

1