JavaScript - .js y .html

 
Vista:

.js y .html

Publicado por Alvaro (2 intervenciones) el 08/03/2013 15:55:22
Amigos:

Siempre me han ayudado asi que no puedo dejar de consultar.

Tengo una web index.html donde quiero poner la fecha con letras, algo asi:
"Viernes 8 de marzo de 2013"

Y tengo un archivo archivo funciones.js donde tengo el script para devolver la fecha

1
2
3
4
5
6
7
function retornarFecha()
{
  var fecha
  fecha=new Date();
  var cadena=dayArray(fecha.getDate())+'/'+(fecha.getMonth()+1)+'/'+fecha.getYear();
  return cadena;
}


Esta funcion me devuelve con numeros: 8/3/13
------------------------

Anteriormente use el siguiente script directamente desde el index.html
Pero ahora quiero hacerlo desde fuera porque si en algun momento debo modificar prefiero hacerlo en un solo archivo en vez de toda la web.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script languaje="JavaScript">
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,","Miércoles,","Jueves,","Viernes,","Sábado,")
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")
document.write("<font color='black' face='Georgia' style='font-size:8pt'>"+dayarray[day]+" "+daym+" de "+montharray[month]+" de "+year+"</font>")
</script>


Este script funciona perfecto, pero directamente desde el index.html

La web es www.elceleste.com.uy ahi pueden ver la fecha con el script funcionando bien.

----------------------------

Otra cosa, quiero agregar un slider (es un recuadro donde van pasando imagenes que derivan a diferentes link) de la misma manera que esta funcion de fecha.

Aqui va el script que funciona directamente en el html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<html>
<head>
Slider<br>
</head>
<body>
<script type="text/javascript">
//Ancho (en pixeles)
var sliderwidth="175px"
//Alto
var sliderheight="100px"
//Velocidad 1-10
var slidespeed=1
//Color de fondo:
slidebgcolor="#f4f9fd"
 
//Vínculos y enlaces de las imágenes
var leftrightslide=new Array()
var finalslide=''
leftrightslide[0]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/ancap.jpg" height="100px"></a>'
leftrightslide[1]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/atos_origin.jpg" height="100px"></a>'
leftrightslide[2]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/cacinos.jpg" height="100px"></a>'
leftrightslide[3]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/cocacola.jpg" height="100px"></a>'
leftrightslide[4]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/dow.jpg" height="100px"></a>'
leftrightslide[5]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/general_elactric.jpg" height="100px"></a>'
leftrightslide[6]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/mc.jpg" height="100px"></a>'
leftrightslide[7]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/omega.jpg" height="100px"></a>'
leftrightslide[8]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/pyg.jpg" height="100px"></a>'
leftrightslide[9]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/samsung.jpg" height="100px"></a>'
leftrightslide[10]='<a href="http://www.cou.org.uy" target="blank" title="Aquí el título"><img border="0" src="http://www.cou.org.uy/cou/slider/visa.jpg" height="100px"></a>'
 
var imagegap=""
var slideshowgap=5
 
 
var copyspeed=slidespeed
leftrightslide='<nobr>'+leftrightslide.join(imagegap)+'</nobr>'
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+leftrightslide+'</span>')
var actualwidth=''
var cross_slide, ns_slide
 
function fillup(){
if (iedom){
cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
actualwidth=document.all? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth
cross_slide2.style.left=actualwidth+slideshowgap+"px"
}
else if (document.layers){
ns_slide=document.ns_slidemenu.document.ns_slidemenu2
ns_slide2=document.ns_slidemenu.document.ns_slidemenu3
ns_slide.document.write(leftrightslide)
ns_slide.document.close()
actualwidth=ns_slide.document.width
ns_slide2.left=actualwidth+slideshowgap
ns_slide2.document.write(leftrightslide)
ns_slide2.document.close()
}
lefttime=setInterval("slideleft()",30)
}
window.onload=fillup
 
function slideleft(){
if (iedom){
if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px"
else
cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+slideshowgap+"px"
 
if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px"
else
cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+slideshowgap+"px"
 
}
else if (document.layers){
if (ns_slide.left>(actualwidth*(-1)+8))
ns_slide.left-=copyspeed
else
ns_slide.left=ns_slide2.left+actualwidth+slideshowgap
 
if (ns_slide2.left>(actualwidth*(-1)+8))
ns_slide2.left-=copyspeed
else
ns_slide2.left=ns_slide.left+actualwidth+slideshowgap
}
}
 
 
if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';background-color:'+slidebgcolor+'" onmouseover="copyspeed=0" onmouseout="copyspeed=slidespeed">')
write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
write('<div id="test3" style="position:absolute;left:-1000px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width="+sliderwidth+" height="+sliderheight+" name="ns_slidemenu" bgcolor="+slidebgcolor+">')
write('<layer left="0" top="0" onmouseover="copyspeed=0" onmouseout="copyspeed=slidespeed" name="ns_slidemenu2"></layer>')
write('<layer left="0" top="0" onmouseover="copyspeed=0" onmouseout="copyspeed=slidespeed" name="ns_slidemenu3"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script></script>
 
</body>
</html>


Bueno, eso es todo.

Espero me puedan ayudar, y vamo arriba laWebDelProgramador

Saludos

Alvin
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder