Bienvenido a Tecnohackers

Tecnohackers » Programacion » Programacion Webmaster » Scripts Pre-Fabricados (Moderador: Zentraedi)
 » 

Códigos en JavaScript



Autor Tema: Códigos en JavaScript  (Leído 1913 veces)

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Códigos en JavaScript
« en: Agosto 05, 2010, 07:32:19 am »

Objetivo: Enviar saludo de bienvenida apenas carguen nuestra   web

Marco Teorico: Para mostrar nuestro saludo apenas se   recargue la pagina debemos usar el evento OnLoad dentro de las   etiquetas body y llamar nuestra función. Después de haber llamado   la función declaramos un función llamada alert que nos mostrara   nuestro mensaje.


Código: You are not allowed to view links. Register or Login
  <html>
 <head>
  <script>
    function saludo(){
      alert("Bienvenido a Mi Pagina WEB, gracias por visitarnos!!!");
    }
  </script>
 </head>
 <body onLoad="saludo()">
 </body>
</html> 
Resultado   You are not allowed to view links. Register or Login

Gracias a 4ng3r

::Así es Volví::

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Re:Códigos en JavaScript
« Respuesta #1 en: Agosto 05, 2010, 07:33:53 am »
Objetivo: Mostrar la fecha actual

Explicación:   Dentro del Código  Sonreir

Código: You are not allowed to view links. Register or Login
  // ***********************************************
// AUTHOR: 4ng3r
// URL: http://angercode.wordpress.com
//  Fecha actual
// ***********************************************
 
//  Instaciamos el objeto que contiene nuestra informacion
var now = new Date();
 
//  Crear dos array's con la info a mostrar
var dias = new Array('Domingo','Lunes','Martes','Miercoles','Jueves','Viernes','Sabado');
var meses = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
 
//  Obtenemos y validamos el dia actual :: si es un dia menor de 10 le acregemos
//  un 0 a su inicio
var fecha = ((now.getDate()<10) ? "0" : "")+ now.getDate();
 
//  Creamo la cadena a imprimir
hoy =  dias[now.getDay()] + ", " + meses[now.getMonth()] + " " + fecha + ", " +(now.getFullYear()) ;
document.write("Hoy es: " +hoy+ ".");
   
Resultado: You are not allowed to view links. Register or Login
 

::Así es Volví::

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Re:Códigos en JavaScript
« Respuesta #2 en: Agosto 05, 2010, 07:35:16 am »
  • Obejtivo: HTML en tiempo REAL

    Explicacion: En este   código simplemente uso el evento onkeyup como fuente de mi poder,   ya que con el controlo cuando el usuario deja de presionar un tecla y   asi llamar mi función javascript, a dentro de mi función concateno y la   voy mostrando.
Código: You are not allowed to view links. Register or Login
<!--
  AUTHOR: 4ng3r
  URL: http://angercode.wordpress.com
  URL: http://foro.project-ric.org
  Editor en Tiempo Real
 -->
<html>
<head>
   <title>HTML TIEMPO REAL</title>
   <script language="JavaScript">
   function verCodigo(htmlText){           
    salida  = " " + htmlText;
    document.getElementById("salida").innerHTML = salida;
   }
 
   </script>
 
   <style type="text/css">
     body{
      background: rgb(51,102,153);
      text-align: center;     
    }
    textarea{
      height: 200px;
      width: 800px;
    }
    textarea:focus{
      border: 3px rgb(255,0,0) ridge
    }
   </style>
</head>
<body>
   <h2>..:: HTML en tiempo real ::..</h2>
   <small>by 4ng3r</small>
   <hr>
   <textarea name="codigo" onkeyup="verCodigo(this.value)"></textarea>
   <hr>
   <fieldset>
    <legend>Mi Codigo HTML</legend>
    <div id="salida"></div>
   </fieldset>
</body>
</html>


Resultado You are not allowed to view links. Register or Login

 
 
« Última modificación: Agosto 05, 2010, 07:41:09 am por char »

::Así es Volví::

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Re:Códigos en JavaScript
« Respuesta #3 en: Agosto 05, 2010, 07:36:34 am »
Objetivo: Ver contraseña escondida en asteriscos

Explicación:   Este código descifra las contraseñas que estan guardadas en el   explorardor

Código: You are not allowed to view links. Register or Login
  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 + "\n"; } } if (s) alert("La pass en esta pagina es:\n\n" + s); else alert("No hay pass en esta pagina.");})();     
« Última modificación: Agosto 05, 2010, 07:38:13 am por char »

::Así es Volví::

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Re:Códigos en JavaScript
« Respuesta #4 en: Agosto 05, 2010, 07:37:59 am »

Objetivo: Validar numero en un formulario

Explicación:   Utilizo la funcion isNaN, esta función devuelve un boleano dependiendo   de si lo que recibe es un número o no.

codigo :

HTML
Código: You are not allowed to view links. Register or Login
  <html>
  <script src="JS000.js" type="text/javascript" language="JavaScript1.5"></script>
 
  <head>
 
  </head>
 
  <body>
   <label>Escriba un Numero</label><br><br>
   <input id="numero" type="text" name="numero">&nbsp;&nbsp;
   <input type="text" name="return" id="return"><br><br>
   <input type="button" onClick="validar()" value="Enviar"><br><br>
  </body>
</html>   
 
JAVASCRIPT


   
     

 
Código: You are not allowed to view links. Register or Login
  function validar(){
  var numero=document.getElementById("numero");
  if(!isNaN(numero.value)){
    document.getElementById("return").value="VERDADERO"
  }else{
    document.getElementById("return").value="FALSO"
  }
Resultado: You are not allowed to view links. Register or Login

::Así es Volví::

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Re:Códigos en JavaScript
« Respuesta #5 en: Agosto 05, 2010, 07:39:52 am »
Objetivo: Centrar un div a cualquier tipo de resolucion

codigo :
Código: You are not allowed to view links. Register or Login
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<script>
function getWindowData(){
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth;
        heightViewport= window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
}
function $(id){
return document.getElementById(id);
}
window.onload=window.onresize=window.onscroll=function(){
var data=getWindowData();
$('pp').style.left=data[0]/2+data[2]-parseInt($('pp').style.width)/2+'px';
$('pp').style.top=data[1]/2+data[3]-parseInt($('pp').style.height)/2+'px';
}
 
</script>
 
</head>
 
<body>
<div id="nada"></div>
<div id="pp" style="border:1px solid #000;position:absolute;width:410px; height:145px;">algo</div> 
</body>
</html>   

::Así es Volví::

Desconectado char

  • Gran Colaborador
  • ****
  • Mensajes: 1149
  • Ingeniero de Sistemas
    • TIC´S
Re:Códigos en JavaScript
« Respuesta #6 en: Agosto 05, 2010, 07:40:54 am »
Objetivo: Agregar fila a nuestra tabla

Código

Código: You are not allowed to view links. Register or Login
  <html>
<head>
<script type="text/javascript">
function insRow()
{
var x=document.getElementById('myTable').insertRow(0);
var y=x.insertCell(0);
var z=x.insertCell(1);
y.innerHTML="NEW CELL1";
z.innerHTML="NEW CELL2";
}
</script>
</head>
 
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="insRow()" value="Insert row">
 
</body>
</html>   

::Así es Volví::

Tags:
Tags:

 


SMF 2.0.19 | SMF © 2016, Simple Machines
Paginas Afiliadas
Twitter - FaceBook - Daraxblog
Designed by Smf Personal