0% encontró este documento útil (0 votos)
189 vistas

Ejemplos Javascript

El documento contiene 10 ejemplos de código JavaScript para realizar diferentes tareas en una página web como mostrar alertas, recoger datos de usuario, abrir ventanas emergentes, mostrar una galería de imágenes y enviar correos electrónicos. Cada ejemplo se encuentra en su propia página HTML.

Cargado por

Vana Vb
Derechos de autor
© © All Rights Reserved
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
189 vistas

Ejemplos Javascript

El documento contiene 10 ejemplos de código JavaScript para realizar diferentes tareas en una página web como mostrar alertas, recoger datos de usuario, abrir ventanas emergentes, mostrar una galería de imágenes y enviar correos electrónicos. Cada ejemplo se encuentra en su propia página HTML.

Cargado por

Vana Vb
Derechos de autor
© © All Rights Reserved
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 13

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.

01 Transitional//EN">

<html>

<head>

<title>ejemplo01.htm</title>

<script language="JavaScript">

//Visualizar un mensaje de bienbenida

alert ("¡Bienvenido a nuestra pagina!");

</script>

</head>

<body>

<a href='ejemplo02.html'> Ir al siguiente ejemplo...</a>

</body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo02.htm</title>

<input type= button value=Atras onclick="history.go(-1)">

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo03.htm</title>

<script language="JavaScript">

//Recoge un dato por teclado y visualizarlo

var nom;

nom=prompt("Escribe tu nombre", "Nombre");

alert("Mucho gusto " + nom);

</script>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo04.htm</title>

<head>

<script language="JavaScript">

//pedir confirmacion para visitar una pagina

function confirmar()

return confirm("Esta pagina contiene contenido para mayores de 18 años. ¡Lo cumples?")

</script>

</head>

<body>

<a href="http://www.starwars.com/" onclick="return confirmar()">

Enlace a la pagina oficial de start wars </a>

</body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo05.htm</title>

<!-- Abrir una ventana pop-up cada cierto tiempo -->

<head>

<script>

function abrir_ventana()

window.open("http://WWW.cnice.mec.es/");

function para_abrir()

clearTimeout(pop);

pop = setInterval ("abrir_ventana()", 3000);

</script>

</head>

<body>

<input type=button value="parar de abrir ventanas"

oneclick="parar_abrir()">

</body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo06.htm</title>

<head>

<script>

//ejemplo lo que visualiza un reloj digital.

function Ver_Hora()

var mihora = new Date();

var horas = mihora.getHours().toString();

var minutos =mihora.getMinutes().toString();

if (minutos.length == 1)minutos = "0" + minutos;

var segundos = mihora.getSeconds().toString();

if (segundos.length == 1)segundos = "0"+ segundos;

document.forms[0].mireloj.value = horas + " : "+ minutos + " : " + segundos;

</script>

</head>

<body>

<form>

<p align="center">

<label><h1>El reloj de willbert</h1></label></p>

<input type="text" size="10" name="mireloj"> </p>

</form>

<script> var r = setInterval ("Ver_Hora()",500); </script>

</body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo07.htm</title>

<head>

<script language="javascript">

//Ejemplo que muestra una galeria de imagenes

function ver_imagen()

if (!document.images)

return

document.images.img.src=

document.imagenes.imagen.options[document.imagenes.imagen.slectedIndex].value

</script>

<body>

<form name="imagenes">

<select name="imagen" size="1" onchange="ver_imagen()">

<option> Elie una imagen </option>

<option value = "img\1.jpg">1 </option>

<option value = "img\2.jpg">2 </option>

<option value = "img\3.jpg">3 </option>

</select>

</form>

<img src="img\1.jpg" name="img" width=600 height=436 border=3>

</body>

</head>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

//profe este ejercicio no funciona ya lo revise letra por letra y nomas no pero de todos modos encontre otro por internet
//que si funciona se lo agrego despues de este

<html>

<title>ejemplo08</title>

<script>

//desabilitar el boton derecho del raton

function boton_derecho(e)

if (navigator.appName == 'Netscape' &&

(e.which == 3 || e.which == 2))

return false;

else if (navigator.appName == 'Microsoft Internet Explorer '&&

(event.button == 2 || event.button == 3))

alert("Lo sentimos, el boton derecho del raton esta

desabilitado.");

return false;

return true;

document.onmousedown = boton_derecho;

if (document.layers) window.captureEvents (Event.MOUSEDOWN);

window.onmousedown = boton_derecho;

</script>

<body> Pulsa el boton derecho... </body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Ejemplo08.htm</title>

<script language=JavaScript>

<!--

var message='NO SIRVE EL BOTON DERECHO DE TU MOUSE, ESTA DESCOMPUESTO,COMPARTE OTRO MAS CHINGON';

function clickIE() {if (document.all) {alert(message);return false;}}

function clickNS(e) {if

(document.layers||(document.getElementById&&!document.all)) {

if (e.which==2||e.which==3) {alert(message);return false;}}}

if (document.layers)

{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}

else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function('return false')

// -->

</script>

</head>

<BODY>

<CENTER>

<h2>Pulsa el boton derecho </h2>

solo para darte cuenta de que no sirve sorry, mejor cierra esta ventana y regresa por donde venistes bye.

<hr>

<center>

<h3> [<a href="ejemplo01.html">Volver</a>] </h3>

</center>

</BODY>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>ejemplo09</title>

<!-- Imprimir un documento -->

<body>

<p align="center" style="font:italic 36px Georgia">GATITO </p>

<p align="center"><img src="Ventana/cat.jpg" width="714" height="471 border="0""></p>

<form >

<input type="button" value="Imprmir" onclick="window.print()">

</form>

</body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<title>Ejemplo10</title>

<!-- Muestra un mensaje con scroll en la barra de estado -->

<head>

<script language="JavaScript">

var timed = 0;

var scrollGo = false;

var delay = 100;

var space = 100;

function scroll_start()

var i=0;

msg="Este es el mensaje mostrado en la barra de estado";

for (i=0;i<space;i++)

msg=" "+msg;

scrollGo = true;

timerid = window.setTimeout ("scrollmsg (0)",delay);

function scrollmsg(pos)

var out = "";

scrollGo = false;

if (pos < msg.length)

self.status = msg.substring(pos,msg.length);

else

pos = -1

++pos;
scrollGo= true;

timerid = window.setTimeout("scrollmsg("+pos+")",delay);

</script>

</head>

<body onLoad="scroll_start();">

</body>

</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<body>

<script language="javascript">

function mailpage()

mail_str = "mailto:[email protected]?subject=Ejemplo: " +

document.title;

mail_str += "&body= te recomiendo que visites esta pagina (http://www.cnice.mec.es/)--" +


document.title;

mail_str += ". Enlace:" + location.href;

location.href = mail_str;

</script>

<a HREF="javascript:mailpage()"> Mandar correo¡</a>

</body>

</html>

También podría gustarte