Conocer los datos del navegador con JavaScript

24 06 2009
<html>
   <body>
   <script type="text/javascript">
   document.write("<p>Navegador: ");
   document.write(navigator.appName + "</p>");

   document.write("<p>Versión del navegador: ");
   document.write(navigator.appVersion + "</p>");

   document.write("<p>Código: ");
   document.write(navigator.appCodeName + "</p>");

   document.write("<p>Plataforma: ");
   document.write(navigator.platform + "</p>");

   document.write("<p>Cookies habilitadas: ");
   document.write(navigator.cookieEnabled + "</p>");

   document.write("<p>Cabecera de agente de usuario del navegador: ");
   document.write(navigator.userAgent + "</p>");
   </script>
   </body>
   </html>




Como actualizar dos iframes al mismo tiempo con JavaScript

24 06 2009
<html>
   <head>
   <script language="javascript">
   function twoframes()    {
           document.all("frame1").src="frame_c.htm";
           document.all("frame2").src="frame_d.htm";
   }
   </script>
   </head>

   <body>
   <iframe src="frame_a.htm" name="frame1"></iframe>
   <iframe src="frame_b.htm" name="frame2"></iframe>
   <br>
   <form>
   <input type="button" onclick="twoframes()" value="Cambiar la URL de los dos iframes">
   </form>
   </body>
   </html>

Escríbanse las cuatro páginas de los frames que se especifican y probar. Es muy sencillo darse cuenta de que la función all nos permite acceder a los distintos elementos de la página, al igual que lo hemos hecho antes de otras formas.





Obtener y cambiar la URL de un formulario.

24 06 2009
<html>
   <head>
   <script type="text/javascript">
   function getAction()
   {
           var x=document.forms.myForm;
           alert(x.action);
   }

   function changeAction(action)
   {
           var x=document.forms.myForm;
           x.action=action;
           alert(x.action);
   }
   </script>
   </head>

   <body>
   <form name="myForm" action="ejemplos.php">
   <input type="button" onclick="getAction()" value="Ver el valor del atributo action">
   <br><br>
   <input type="button" onclick="changeAction('hola.php')" value="Cambiar el valor del atributo action">
   </form>
   </body>
   </html>

En este ejemplo podemos ver otra forma de utilizar los formularios en el código JavaScript.





Seleccionar el texto de un cuadro de texto y darle el foco

24 06 2009
<html>
   <head>
   <script type="text/javascript">
   function setfocus()
   {
           document.forms[0].txt.select();
           document.forms[0].txt.focus();
   }
   </script>
   </head>

   <body>
   <form>
   <input type="text" name="txt" size="30" value="¡Hola mundo!">
   <input type="button" value="Selecciona texto" onclick="setfocus()">
   </form>
   </body>
   </html>

Como podemos ver, es posible conseguir el contenido de los formularios de la página por medio de la matriz forms[] de document.





Cómo conseguir que un enlace gane o pierda el foco de entrada.

24 06 2009
<html>
   <head>
   <style type="text/css">
   a:active {color:blue}
   </style>
   <script type="text/javascript">
   function getfocus()
   {
           document.getElementById('w3s').focus();
   }

   function losefocus()
   {
           document.getElementById('w3s').blur();
   }
   </script>
   </head>

   <body>
   <a id="w3s" href="http://www.google.com">Visita Google.com</a>

//solo por presentacion
   <form>
   <input type="button" onclick="getfocus()" value="Coge el foco">
   <input type="button" onclick="losefocus()" value="Pierde el foco">
   </form>
   </body>
   </html>