Foros del Web » Programando para Internet » Javascript »

Scripts varios - Un regalo para uds.

Estas en el tema de Scripts varios - Un regalo para uds. en el foro de Javascript en Foros del Web. 1- <html> <body> <!-- Copiar dentro del tag BODY --> <A HREF="javascript :if (self.parent.frames.length != 0) { self.parent.location=document.location.href;}" onMouseOver="window.status='Click aqui'; return true" OnMouseOut="window.status= ''; return ...
  #1 (permalink)  
Antiguo 17/11/2002, 21:38
 
Fecha de Ingreso: julio-2002
Ubicación: Buenos Aires - Argentina
Mensajes: 255
Antigüedad: 21 años, 9 meses
Puntos: 0
Scripts varios - Un regalo para uds.

1-
<html>
<body>
<!-- Copiar dentro del tag BODY -->
<A HREF="javascript:if (self.parent.frames.length != 0) { self.parent.location=document.location.href;}" onMouseOver="window.status='Click aqui'; return true" OnMouseOut="window.status= ''; return true">
Quitar frames? Click aqui</A>
</body>
</html>

Este script te permite romper los marcos de una pagina


2- Este script te permite navegar por el sitio con las teclas del teclado

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var key = new Array(); // Define key launcher pages here
key['h'] = "http://javascript.internet.com/index.html";
key['f'] = "http://javascript.internet.com/feedback.html";
key['n'] = "http://javascript.internet.com/new.html";
key['s'] = "http://javascript.internet.com/toc.html";

function getKey(keyStroke) {
isNetscape=(document.layers);
// Cross-browser key capture routine couresty
// of Randy Bennett ([email protected])
eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
which = String.fromCharCode(eventChooser).toLowerCase();
for (var i in key) if (which == i) window.location = key[i];
}
document.onkeypress = getKey;
// End -->
</script>
</HEAD>

<!-- Copiar dentro del tag BODY -->

<BODY>

<center>
<table border=0><tr><td>
<pre>
This site equipped with Key Launcher!

The following launcher keys are available:

Press the letter 'h' for: Home Page
Press the letter 'f' for: Feedback Page
Press the letter 'n' for: What's New Page
Press the letter 's' for: Site Contents
</pre>
</td></tr></table>
</center>

</BODY>


3- Detecta OS

<body>

<script>

//This Script is Copyright S Atamian© 2000
//If you are going to use this code, you MUST leave these
//lines of script UNEDITED!

if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('98') != -1))
{
alert('Using Windows 98! Good for you!')
}
if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1))
{
alert('You are using Windows 95 to access my page! Come back when you upgrade to 98!')
}
else
if(navigator.userAgent.indexOf('Mac') != -1)
{
alert('EEEEEEEWWWWWW! YOU ARE USING A MAC! Get the hell out of here!')
}

</script>
</body>


4- Caducar una pagina

<html>
<head>
<!-- Copiar dentro del tag HEAD -->
<meta HTTP-EQUIV="Expires" CONTENT="0">
<script LANGUAGE="JavaScript">

<!--
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var favorite = GetCookie('advertencia');

if (favorite != null) {
switch (favorite) {
case 'caduca' : url = 'caducado.htm';
break;
}
window.location.href = url;
}
// -->
</script>

</head>

<body>

<input type="button" name="caduca" onClick="SetCookie('advertencia', this.name, exp);" value="Caducar Página">
</body>
</html>


5- Cuenta Clicks en js

<html>
<body>
<!-- Copiar dentro del tag BODY -->
<SCRIPT>
var i = 0
</SCRIPT>

Click <a href="http://www.sitio.com" onClick= "
javascript:
i = i + 1
if (i == 1) {
window.status= 'Ejemplo, hiciste click ' + i + ' veces en este link.'
}
else
{
window.status= 'Ejemplo, hiciste click ' + i + ' veces en este link'
}
;return false"> acá </a> muchas veces y mira la barra de estado.
</body>
</html>



7- Reemplazar String

<SCRIPT LANGUAGE="JavaScript">
String.prototype.replace = StringReplace;
function StringReplace( findText, replaceText ) {
var originalString = new String(this);
var pos = 0;

// Validate parameter values
if (findText+"" != "undefined" || findText == null || findText == "")
return originalString;
if (replaceText+"" != "undefined" || replaceText == null)
return originalString;

var len = findText.length;
var limit = originalString.length;

pos = originalString.indexOf(findText);
while (pos != -1 && i < limit) {
// Get the first and last parts of the string: preString + findText + postString
// then change to preString + replaceText + postString to replace findText
preString = originalString.substring(0, pos);
postString = originalString.substring(pos+len, originalString.length);
originalString = preString + replaceText + postString;
pos = originalString.indexOf(findText);
i++;
}

return originalString;
}
</SCRIPT>


8- Validar caracteres alfanumericos

<SCRIPT LANGUAGE="JavaScript">
function IsAlphaNum( str ) {
// Return immediately if an invalid value was passed in
if (str+"" == "undefined" || str+"" == "null" || str+"" == "")
return false;

var isValid = true;

// convert to a string for performing string comparisons.
str += "";

// Loop through length of string and test for any alpha numeric
// characters
for (i = 0; i < str.length; i++)
{
// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
if (!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) ||
((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))))
{
isValid = false;
break;
}
} // END for

return isValid;
} // end IsAlphaNum
</SCRIPT>



9- Valida numeros integrales


<SCRIPT LANGUAGE="JavaScript">
function IsInt( numstr, allowNegatives ) {
// Return immediately if an invalid value was passed in
if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")
return false;

// Default allowNegatives to true when undefined or null
if (allowNegatives+"" == "undefined" || allowNegatives+"" == "null")
allowNegatives = true;

var isValid = true;

// convert to a string for performing string comparisons.
numstr += "";

// Loop through string and test each character. If any
// character is not a number, return a false result.
// Include special case for negative numbers (first char == '-').
for (i = 0; i < numstr.length; i++) {
if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || (numstr.charAt(i) == "-"))) {
isValid = false;
break;
} else if ((numstr.charAt(i) == "-" && i != 0) ||
(numstr.charAt(i) == "-" && !allowNegatives)) {
isValid = false;
break;
}

} // END for

return isValid;
} // end IsInt
</SCRIPT>



10- Obtiene fecha actual

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
Date.prototype.getActualDay = GetActualDay;
function GetActualDay() {
return this.getDay() + 1;
}
//-->
</SCRIPT>


11- Muestra la fecha actual en la página


<html>
<body>
<!-- Copiar dentro del tag BODY -->
<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","Miercoles","Juev es","Viernes","Sabado")
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Ju nio","Julio","Agosto","Septiembre","Octubre","Novi embre","Diciembre")
document.write("<small><font color='000000' face='Arial'>"+dayarray[day]+" "+daym+" de "+montharray[month]+" de "+year+"</font></small>")

</script>
</body>
</html>


12- Reloj digital


<html>
<head>
<!-- PRIMER PASO: Copiar dentro del tag HEAD -->
<script language="JavaScript1.2">
<!--

function hora(){
if (!document.layers&&!document.all)
return
var Digital=new Date()
var horas=Digital.getHours()
var minutos=Digital.getMinutes()
var segundos=Digital.getSeconds()
var dn="AM"
if (horas>12){
dn="PM"
horas=horas-12
}
if (horas==0)
horas=12
if (minutos<=9)
minutos="0"+minutos
if (segundos<=9)
segundos="0"+segundos
mrelog=""+horas+":"+minutos+":"
+segundos+" "+dn+""
if (document.layers){
document.layers.relog.document.write(mrelog)
document.layers.relog.document.close()
}
else if (document.all)
relog.innerHTML=mrelog
setTimeout("hora()",1000)
}
//-->
</script>
</head>

<body>
<!-- SEGUNDO PASO: Copiar dentro del tag BODY -->
<body onload="hora()">
<!-- Coloca esta etiqueta donde quieras ver el relog -->
<span id="relog" style="position: absolute"></span>
</body>
</html>



Espero que los disfruten y saludos
__________________
Pablo Maurelli
Noc IT - Monitoreo y Administración de Red
Gerencia de Infraestructura IT
E-Mail: [email protected] (MSN)
  #2 (permalink)  
Antiguo 17/11/2002, 22:16
Colaborador
 
Fecha de Ingreso: julio-2002
Ubicación: Buenos Aires
Mensajes: 699
Antigüedad: 21 años, 9 meses
Puntos: 1
me parece a mí, o los sacaste del scriptmaster?
  #3 (permalink)  
Antiguo 04/03/2003, 16:17
Avatar de Blusera80  
Fecha de Ingreso: noviembre-2001
Ubicación: BS.AS.
Mensajes: 249
Antigüedad: 22 años, 5 meses
Puntos: 0
Desacuerdo

Yo utilice estos scripts que este muchacho tan gentil nos paso, y los unicos que use estan mal

En este momento son las 6 de la tarde y el escript dice 6 Am

Hoy es martes y el script dice miercoles

PORQUE??????????

__________________
eMe Cher
  #4 (permalink)  
Antiguo 04/03/2003, 16:35
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Buenas,

ese script contempla la posibilidad de que si el año que saca es menor a 1000 le sume 1900, con lo que según y en qué ordenador dirá que es el año 1903

Parece un poco desfasado. Busca en las FAQ, seguramente encontrarás alguno actualizado
  #5 (permalink)  
Antiguo 04/03/2003, 21:01
Avatar de Blusera80  
Fecha de Ingreso: noviembre-2001
Ubicación: BS.AS.
Mensajes: 249
Antigüedad: 22 años, 5 meses
Puntos: 0
De acuerdo

CHasgracias!!!!!!!

Ya lo solucione, tenia mal la fecha y el dia en mi pc!!!
__________________
eMe Cher
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




La zona horaria es GMT -6. Ahora son las 10:46.