PDA

Ver versión completa : f.a.q javascript , esto nuncaacavara


logamweb
13-sep-2005, 18:30
********************
Hola con todos , el presente es un recopilado de preguntas relacioandas con javascript , algunas fueron tomadas de internet y algunas (muy pocas) , fueron creados por su amigo Logamweb
, espero , se unan ala encuesta y me permitan saver su opinion sobre estas F.A.Q , si tiene dudas sobre java script , por favor creen un nuevo post y pongan hay sus preguntas , y gustosamente seran respondidas , no llenemos este post con preguntas sin sentido
por favor , lo que se busca es crear una especia de diccionario con preguntas y respuestas , muchas gracias , espero me hayan comprendido , no olviden votar ok [-o<
********************
.- Navegar con un menú desplegable (select)
<select name="select" onChange="location.href=this.value">
<option value="paginauno.html">Pagina 1</option>
<option value="paginados.html">Pagina 1</option>
<option value="paginatres.html">Pagina 1</option>
</select>


.- Deshabilitar selección de texto
<script language="JavaScript">
function disableselect(e)
{
return false
}
function reEnable()
{
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar)
{
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>


P . ¿Cómo crear botón de "guardar como..."?
<HTML>
<HEAD>
<script language="javascript">
function guardarcomo()
{
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(4, 0);
WebBrowser1.outerHTML = "";
}
</script>
</HEAD>
<BODY>
Oprime el botón para guardar esta página...<BR>
<input type="submit" value=" Guardar " onClick=guardarcomo() name="miboton">
</BODY>
</HTML>

Dar estilos CSS para los links
P: ¿como doy estilos CSS a los hipervinculos?
CAMBIA COLOR AL PASAR EL RATÓN POR LO ALTO DEL ENLACE...

<a href="" onmouseover="this.style.color='red';" onmouseout="this.style.color='';">This HREF turns red on hover.</a>

----------------------------------------------------------------
HIPERVINCULOS O LINKS DE COLOR VERDE.

<a href="" style="color:green;">This HREF is green.</a>


-----------------------------------------------------------------------
HIPERVINCULO SIN RAYA POR DEBAJO

<a href="" style="text-decoration: none;">This HREF has no underline.</a>

---------------------------------------------------------------------
LINEA DE ESPACIO DE UN HIPERVINCULO

<a href="" style="line-spacing:150%;">These HREFs are spaced 150% of normal.</a>
<a href="" style="line-spacing:150%;">These HREFs are spaced 150% of normal.</a>

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

ESPACIO ENTRE LOS CARACTERES DE UN HIPERVINCULO

<a href="" style="letter-spacing:5px;">This HREF has 5 pixels between letters</a>
-----------------------------------------------------------------------

COLOR DE FONDO EN LOS LINKS

<a href="" style="background:ffffcc;">This HREF has a yellow background.</a>
-----------------------------------------------------------------------




P ¿Como detecto flash player?
<script language="JavaScript"><!--
function MM_checkPlugin(plgIn, theURL, altURL, autoGo) {
var ok=false; document.MM_returnValue = false;
with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
ok=(plugins && plugins[plgIn]);
} else if (appVersion.indexOf('3.1')==-1) {
if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
else ok=autoGo; }
if (!ok) theURL=altURL; if (theURL) window.location=theURL;
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" onLoad="MM_checkPlugin('Shockwave Flash','index.html','http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;Lang=L atinAmerica&amp;P5_Language=Spanish',true);return document.MM_returnValue">

P¿Como detecto shockwave player?
<!--
function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v4.0
var ok=false; document.MM_returnValue = false;
with (navigator) if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
ok=(plugins && plugins[plgIn]);
} else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) ok=window.MM_flash;
else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) ok=window.MM_dir;
else ok=autoGo; }
if (!ok) theURL=altURL; if (theURL) window.location=theURL;
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" onLoad="MM_checkPlugin('Shockwave for Director','index.html','http://www.macromedia.com/shockwave/download/download.cgi?Lang=LatinAmerica&amp;P5_Language=Spanish ',true);return document.MM_returnValue">













P: ¿Cómo puedo hacer para que cada vez que se abra una página muestre un banner aleatorio, ya sea un archivo swf o un archivo gif?
<html>
<head>
<title>Selección de Banners Aleatorios</title>
</head>

<body>
<SCRIPT LANGUAGE="JavaScript">


width="468"; //Anchura del banner
height="60"; //Altura del banner

banners= new Array();
banners[0]="banner1.gif";
banners[1]="banner2.gif";
banners[2]="banner3.swf";
banners[3]="banner4.gif";
banners[4]="banner5.swf";

totalbanners = banners.length;
var ahora = new Date()
var segundos = ahora.getSeconds()
var ad = segundos % totalbanners;
seleccionado=banners[ad];
localizador=seleccionado.lastIndexOf('.');
localizador2=localizador+4
extension=seleccionado.substring(localizador+1,loc alizador2);
archivo=seleccionado.substring(0,localizador);

document.write("<center>");
if (extension=="swf"){
flash=seleccionado;
document.write('<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=' + width + ' height=' + height + ' CODEBASE=\"http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0\">');
document.write('<PARAM NAME=\"MOVIE\" VALUE=\"' + flash + '\">');
document.write('<PARAM NAME=\"PLAY\" VALUE=\"true\">');
document.write('<PARAM NAME=\"LOOP\" VALUE=\"true\">');
document.write('<PARAM NAME=\"QUALITY\" VALUE=\"high\">');
document.write('<EMBED SRC=' + flash + ' width=' + width + ' height=' + height + ' PLAY=\"true\" LOOP=\"true\" QUALITY=\"high\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi? P1_Prod_Version=ShockwaveFlash\">');
document.write('</EMBED>');
document.write('</OBJECT>');}
else {document.write('<img src='+seleccionado+' width='+width+' height='+height+'>');
document.write('</center>');}
// Fin

</SCRIPT>

<!-- RESTO DE PÁGINA-->
</body>
</html>


P: ¿Como se puede manipular mediante JavaScript los botones "Atrás", "Adelante" y "Recargar" del navegador?
<html>
<head>
</head>
<body>
<b>Manipular una páginia individual o frame actual</b><br>
<a href="javascript:history.reload()">Recargar esta página o frame</a><br>
<a href="javascript:history.back()">Ir a página (o frame) anterior</a><br>
<a href="javascript:history.forward()">Ir a página (o frame) siguiente</a><br><br>
<b>Manipular un frame vecino</b><br>
<a href="javascript:parent.frames[2].history.reload()">Recargar un frame vecino</a><br>
<a href="javascript:parent.frames[2].history.back()">Ir a frame vecino anterior</a><br>
<a href="javascript:parent.frames[2].history.forward()">Ir a frame vecino siguiente</a><br><br>
<b>Manipular un frame vecino usando su nombre</b><br>
<a href="javascript:parent.nombreDelFrame.history.reload()">Recargar un frame vecino (por nombre)</a><br>
<a href="javascript:parent.nombreDelFrame.history.back()">Ir a frame vecino anterior (por nombre)</a><br>
<a href="javascript:parent.nombreDelFrame.history.forward() ">Ir a frame vecino siguiente (por nombre)</a><br><br>
</body>
</html>

logamweb
13-sep-2005, 18:33
P.- ¿Cómo substituir los botones de un formulario por imágenes?
<FORM name="frm" method="post" ACTION="javascript:alert('Este formulario no hace nada')">
<INPUT type="text" name="campo1">
<INPUT type="text" name="campo2">
<A href="javascript:document.frm.submit();"><IMG src="imagen_submit.gif" border="0"></A>

<A href="javascript:document.frm.reset();"><IMG src="imagen_reset.gif" border="0"></A>
</FORM>


P.-¿Como redireccionar a una página? esto no es java script , pero siempre buscan esto en las secciones de java
poner esto entre head
<META HTTP-EQUIV="Refresh" CONTENT="@;URL=http://www.tusitioweb.com">

Validación del formato de una dirección de correo
<html>
<head>
<script language="JavaScript">
function Validar(form){
var pos1, pos2, bOk = true;
var sDir = document.frm.dir.value;
if (sDir == ""){
alert("Por favor ingrese su dirección de correo");
document.frm.dir.focus();
return false;
}
pos1 = sDir.indexOf('@', 0);
pos2 = sDir.indexOf('.', 0);
bOk = bOk && (pos1 > 0);
bOk = bOk && (pos2 != -1);
bOk = bOk && (pos1 < pos2 - 1);
bOk = bOk && (pos2 < sDir.length - 1);
if (!bOk){
alert("Dirección de correo inválida");
document.frm.dir.focus();
return false;
}
}
</script>
</head>
<body>
<form name="frm" method="post" action="" onSubmit="return Validar(this);">
Dirección de correo:
<input type="text" name="dir">
<input type="submit">
</form>
</body>
</html>



P: ¿Como puedo hacer que una ventana se abra simulando un efecto de explosión?
<html>
<head>
</head>
<body>
<script language="JavaScript">

var ancho = 100
var alto = 100
var fin = 300
var x = 100
var y = 100

function inicio(){
ventana = window.open("hola.htm", "_blank", "resizable,height=1,width=1,top=x,left=y,screenX=x, screenY=y");
abre();
}

function abre(){
if (ancho <= fin) {
ventana.moveTo(x, y);
ventana.resizeTo(ancho, alto);
x += 5;
y += 5;
ancho += 15;
alto += 15;
timer = setTimeout("abre()", 1);
} else {
clearTimeout(timer);
}
}

</script>
<form>
<input type="button" value="Abrir Ventana" onClick="inicio()"></p>
</form>
</body>
</html>


Reloj en la barra de estado
<HTML>
<TITLE>Status Hora y día</TITLE>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Script by: Francis Woodhouse (francis@contessa.u-net.com) -->

<!--
function runClock() {
theTime = window.setTimeout("runClock()", 1000);
var today = new Date();
var display= today.toLocaleString();
status=display;
}
// -->
</SCRIPT>


<body onLoad="runClock()">

</body>
</html>


P: ¿Como puedo dar los buenos días a mi amigo o visitante y que siempre que entre a mi sitio le de los buenos días?

R: Con una cookie

<script language="Javascript">
<!--
/*-- for(unknown){ unknown@theoffspring.com } --
Do N't Move Here is unKnown Production's --*/
var today = new Date();
var hora=today.getHours();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // 28 dias
function setCookie(name, value)
{
document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}

function lee(valor)
{
document.cookie.search(RegExp("("+valor+"=)([^;]*)(;*)","gi"))
return unescape(RegExp.$2)
}
if(lee('usass'))
var usuario = lee('usass')
else{
var u=prompt("Introduce tu Nombre","")
if(u){setCookie('usass',u);usuario=u}
else{usuario = "Usuario"}
}
if (hora<6)
alert(usuario+" Hoy has madrugado mucho...¿O no te has acostado?");
else if (hora<12)
alert(usuario+" Buenos d&iacute;as");
else if (hora<=18)
alert("Buenas Tardes "+usuario);
else alert("Buenas Noches "+usuario);
</script>

__________________


P.-¿Cómo evitar que tu página se cargue en un frame externo?
poner en el head
<script>
if (parent.frames.length > 0) parent.location.href = self.document.location
</script>

P: ¿Como puedo contar el número de palabras dentro de un textarea?
<html>
<head>
<script language="JavaScript">
function calcula(){
var sTxt = document.frm.txt.value;
var sTx2 = "";
var sSep = document.frm.sep.value;
var iRes = 0;
var bPalabra = false;
for (var j = 0; j < sTxt.length; j++){
if (sSep.indexOf(sTxt.charAt(j)) != -1){
if (bPalabra) sTx2 += " ";
bPalabra = false;
} else {
bPalabra = true;
sTx2 += sTxt.charAt(j);
}
}
if (sTx2.charAt(sTx2.length - 1) != " ") sTx2 += " ";
for (var j = 0; j < sTx2.length; j++)
if (sTx2.charAt(j) == " ") iRes++;
if (sTx2.length == 1) iRes = 0;
alert("Número de palabras: " + String(iRes));
}
</script>
</head>
<body>
<form name="frm">
Texto:<br>
<textarea name="txt" rows="5" cols="80"></textarea><br><br>
Separadores:
<input type="text" name="sep" value=" ,.;:"><br><br>
<input type="button" name="btn" value="Calcular" onclick="calcula()">
</form>
</body>
</html>



P: ¿Como puedo hacer para que la pagina solo se pueda abrir como popup, y si se abre en modo normal se cierre??
<body onLoad="if (!opener) window.close()">

Detectar Resolución y Redireccionar
<html>
<head>
<script>
var res, url
if ((screen.width == 800) && (screen.height == 600)){
res="800x600"
url="800x600.htm"}
else if ((screen.width == 1024) && (screen.height == 768)){
res="1024x768";
url="1024x768.htm"}
else if ((screen.width == 1152) && (screen.height == 864)){
res="1152x864";
url="1152x864.htm"}
else if ((screen.width == 1280) && (screen.height == 1024)){
res="1280x1024";
url="1280x1024.htm"}
else{
window.location.href = "otra.htm"}
function Entrar(){
window.location.href=url}
</script>
</head>
<body>
Tu Resolución de Pantalla es: <b><script>document.write(res)</script></b><br>
<a href="javascript:Entrar()">Acceda a la página correspondiente a tu resolución</a>
</body>
</html>


P.- ¿Cómo puedo redireccionar una página a otra pasados unos segundos?
<html>
<head>

</head>

<body style="font:bold 10px/15px verdana;color:navy">
<script>



var segundos=3
var direccion='http://www.webareyou.com'
var mensaje="Nos hemos trasladado."

milisegundos=segundos*1000
window.setTimeout("window.location.replace(direccion);",milisegundos);
document.write(mensaje+" Si pasados "+segundos+ " segundos no es redireccionado pinche <a href='"+direccion+"'>aquí</a>.");
</script>

</body>
</html>


P: ¿Como puedo colocar en mi página una frase distinta cada día de la semana?
<html>
<head>
<script language="JavaScript">
function frase(){
var aFrases = new Array("Texto del Domingo",
"Texto del Lunes",
"Texto del Martes",
"Texto del Miércoles",
"Texto del Jueves",
"Texto del Viernes",
"Texto del Sábado");
var fecha = new Date();
var indice = fecha.getDay();
return aFrases[indice];
}
</script>
</head>
<body>
<form name="frm">
<h1>
<script language="JavaScript">
document.write(frase());
</script>
</h1>
</form>
</body>
</html>

logamweb
24-sep-2005, 00:04
primero ponemos esto en la parte mas alta del body <SCRIPT>

function acceso(){

window.location = "zonapasword/" + document.formclave.nick.value + "a-a" + document.formclave.clave.value + ".htm"

}

</SCRIPT> , luego creas un formulario como este <FORM name=formclave>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="100%">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" style="color: #0000FF">
<p align="center">
<input size="10" name=nick value="Usuario">
<br>

Password<br><INPUT type=password name=clave size="10"><br><br><input type="button" value=" Acceder " style="font-size: 8 pt; color: #FF0000; background-color: #53A9FF; border: 2 ridge #000080" onclick="acceso()"> </td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</form>


ahora te expico como funciona esto

creas metalmente un usuario y un pasword , digamos

user: evidali
pasword: foros

entonces creamos un htm , con este nombre evidalia-aforos.htm , lo guardas en una carpeta con nombre digamos zonapasword y listo , como notaras el codigo y el user van separados por las letras a-a


no se necesita ser un genio para entender esto , espero hos sirva bye bye

diodozener33
26-may-2006, 01:53
logamweb, buenas noches he estado mirando como hacer una web con usuario y contraseña pero no me carga la web , a ver si me explico, cree un archivo que se llama admin.htm con esto dentro

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Password</title>
</head>

<body>
<SCRIPT>

function acceso(){

window.location = "zonapasword/" + document.formclave.nick.value + "miusuario-micontraseña" + document.formclave.clave.value + ".htm"

}

</SCRIPT>
</body>
<FORM name=formclave>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="100%">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" style="color: #0000FF">
<p align="center">
<input size="10" name=nick value="Usuario">
<br>

Password<br><INPUT type=password name=clave size="10"><br><br><input type="button" value=" Acceder " style="font-size: 8 pt; color: #FF0000; background-color: #53A9FF; border: 2 ridge #000080" onclick="acceso()"> </td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</form>

</html>

y des pues cree otro con el nombre miusuario-micontraseña.html

despues lo subo, el admin.htm lo dejo de raiz........./admin.html y en esta carpeta crea una que se llama ........./zonapasword/
y dentro de ella meto el archivo ...../zonapasword/miusuario-micontraseña.html

pero ese archivo no se me carga. me puedes decir en qe estoy fallando. gracias por las notas que has dejado por todo el foro creo qe eres de lo mas claro hablando de WEB

logamweb.
08-jul-2006, 02:31
lamento decirte ke la faq la estoy terminando aca http://foro.peruservicios.com/index.php si gustas puedes vsitarlo ..