Foros del Web » Programando para Internet » Javascript »

pasar este script a una archivo .js

Estas en el tema de pasar este script a una archivo .js en el foro de Javascript en Foros del Web. hola tengo este script y necesito hacerlo en un archivo js para que no ocupe tanto espacio en la pagina. y luego llamarlo desde dicha ...
  #1 (permalink)  
Antiguo 14/07/2006, 14:19
 
Fecha de Ingreso: octubre-2005
Mensajes: 407
Antigüedad: 18 años, 6 meses
Puntos: 2
pasar este script a una archivo .js

hola tengo este script y necesito hacerlo en un archivo js
para que no ocupe tanto espacio en la pagina.

y luego llamarlo desde dicha pagina

pero no se como se hace


Código HTML:
<body onLoad="show5()">

<script>
var mydate=new Date();
var year=mydate.getYear();
if (year < 1000)
year+=1900;
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
if (daym<10)
daym="0"+daym;
var dayarray=new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
document.write("<small><font color='000000' face='Arial'><b>"+ dayarray[day] + " " + daym + " de " + montharray[month] + " de " + year + "</b></font></small>");
</script>
<span id="liveclock" >
</span>
<script language="JavaScript">
<!--
function show5(){
if (!document.layers&&!document.all&&!document.getElementById)
return
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()

if (hours<10){
hours= "0" + hours
}
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here to your desire
myclock=""+hours+":"+minutes+":"
+seconds+""

if (document.layers){
document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}
else if (document.all)
liveclock.innerHTML=myclock
else if (document.getElementById)
document.getElementById("liveclock").innerHTML=myclock
setTimeout("show5()",1000)
}
//-->
</script>
</body> 
alguien me ayuda?
__________________
DJJJ
  #2 (permalink)  
Antiguo 15/07/2006, 12:35
 
Fecha de Ingreso: octubre-2005
Mensajes: 407
Antigüedad: 18 años, 6 meses
Puntos: 2
alguien sabe?

alguien puede ayudarme??
__________________
DJJJ
  #3 (permalink)  
Antiguo 15/07/2006, 13:10
Avatar de fer10  
Fecha de Ingreso: octubre-2005
Ubicación: Guadalajara - Mexico
Mensajes: 905
Antigüedad: 18 años, 6 meses
Puntos: 4
mete todo a un .js y lo mandas a llamar en la pagina y si queires que se ejecuten cosas en alguna linea como por ejemplo el document.write() mete eso a una fucnion y la mandas a llamar el la linea dodne quieres que lo escriba..

recuerda poner el src del .js en head..

te recomindo que cuando no necesite usar .js uses un lenjuaje de servidor ya que no te puedes fiar que simpre existira js en el navegador del usario.
__________________
Saludos
FT.
www.fernando.com.mx
  #4 (permalink)  
Antiguo 15/07/2006, 13:19
 
Fecha de Ingreso: octubre-2005
Mensajes: 407
Antigüedad: 18 años, 6 meses
Puntos: 2
seria algo asi? no me anda :(

ejemplo.js

Código HTML:
funcion fechahora()

<script>
var mydate=new Date();
var year=mydate.getYear();
if (year < 1000)
year+=1900;
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
if (daym<10)
daym="0"+daym;
var dayarray=new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
document.write("<small><font color='000000' face='Arial'><b>"+ dayarray[day] + " " + daym + " de " + montharray[month] + " de " + year + "</b></font></small>");
</script>
<span id="liveclock" >
</span>
<script language="JavaScript">
<!--
function show5(){
if (!document.layers&&!document.all&&!document.getElementById)
return
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()

if (hours<10){
hours= "0" + hours
}
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here to your desire
myclock=""+hours+":"+minutes+":"
+seconds+""

if (document.layers){
document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}
else if (document.all)
liveclock.innerHTML=myclock
else if (document.getElementById)
document.getElementById("liveclock").innerHTML=myclock
setTimeout("show5()",1000)
}
//-->
</script> 
y en la index.htm

Código HTML:
<head>
<script language="JavaScript" src="ejemplo.js"></script>
</head>

<body>
fechahora()
</body> 
__________________
DJJJ
  #5 (permalink)  
Antiguo 15/07/2006, 21:23
Avatar de fer10  
Fecha de Ingreso: octubre-2005
Ubicación: Guadalajara - Mexico
Mensajes: 905
Antigüedad: 18 años, 6 meses
Puntos: 4
en el js. solo deves poner javascript nada de HTML.

ejemplo.js
Código:
var mydate=new Date();
var year=mydate.getYear();
if (year < 1000)
year+=1900;
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
if (daym<10)
daym="0"+daym;
var dayarray=new Array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
document.write("<small><font color='000000' face='Arial'><b>"+ dayarray[day] + " " + daym + " de " + montharray[month] + " de " + year + "</b></font></small>");

function show5(){
if (!document.layers&&!document.all&&!document.getElementById)
return
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()

if (hours<10){
hours= "0" + hours
}
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here to your desire
myclock=""+hours+":"+minutes+":"
+seconds+""

if (document.layers){
document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}
else if (document.all)
liveclock.innerHTML=myclock
else if (document.getElementById)
document.getElementById("liveclock").innerHTML=myclock
setTimeout("show5()",1000)
}
Código HTML:
<!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" xml:lang="en" lang="en">
<head>
<title>Untitled</title>
<meta name="generator" content="MAX's HTML Beauty++ 2004" />
<script language="JavaScript" src="ejemplo.js"></script>
</head>

<body onLoad="show5()">
<span id="liveclock" ></span>

</body>
</html> 
__________________
Saludos
FT.
www.fernando.com.mx
  #6 (permalink)  
Antiguo 17/07/2006, 07:16
 
Fecha de Ingreso: octubre-2005
Mensajes: 407
Antigüedad: 18 años, 6 meses
Puntos: 2
muchas gracias fer10

muchas gracias fer10, estaba encamindado, pero realmente no me salia.
probe como dijiste y anda muy bien

graciasss
__________________
DJJJ
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 08:59.