Páginas

martes, 24 de junio de 2014

JavaScript Window (BOM) The browser Object Model. 001

Empezaremos con "El objeto Window". 

Hablando con el navegador. 

"window object" es soportado por todos los navegadores.
 Representa la ventana del navegador.

window.document.getElementById("header");
document.getElementById("header");

Todas los objetos globales JavaScript y variables automáticamente se convierten en miembros de objeto windows.

  • Las variables globales son propiedades del objeto window. 
  • Las funciones son métodos del objeto window. 

Window Size.
Propiedades:
Tenemos a nuestra disposición tres propiedades básicas para modificar el tamaño de nuestro navegador.
(Aclaremos que incluye la parte visible menos el scrolbars y las toolsbars). 

Para IE, Chrome, Firefox, Opera y Safari:
window.innerHeight
window.innerWidth 

Para IE 8, 7, 6, 5: 
document.documentElement.clientHeight
document.documentElement.clientWidth
o
document.body.clientHeight
document.body.clientWidth

La solución más conveniente para todos los navegadores sería similar a esta:

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;

var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;

x=document.getElementById("demo");
x.innerHTML="Browser inner window width: " + w + ", height: " + h + "."
</script>

</body>
</html>

Otros métodos para trabajar con window serían:
window.open() - open a new window
window.close() - close the current window
window.moveTo() -move the current window
window.resizeTo() -resize the current window

No hay comentarios:

Publicar un comentario