JavaScript Tutorial/Window/Introduction

Материал из Web эксперт
Перейти к: навигация, поиск

Creating Windows

The open method can be used to create any primary or secondary window.



   <source lang="javascript">

window.open("web.html", "newWin", "resizeable,menubar,toolbar");</source>


This creates a window that is resizable, contains a menu bar, and has a toolbar.

The "web.html" is the file that will open in the newly created window.

"newWin" represents the name of the window object.

Other features include outerHeight, outerWidth, innerHeight, innerWidth, alwaysRaised, alwaysLowered, location, screenY, and screenX.

The features are specified in the parameters of the open function.

Parent Code for Window Example

   <source lang="javascript">

<HTML>

   <HEAD>
   <TITLE> Window Example - Parent</TITLE>
   <SCRIPT LANGUAGE="Javascript">
   
   </SCRIPT>
   </HEAD>
   <BODY>

   Window Example - Parent Window
   


   <FORM NAME="parentForm">
   Click on the Button below to open a Child window:
   

<INPUT TYPE="button" NAME="submit" VALUE="Open Child Window" onclick="openWin()">


<INPUT TYPE="text" NAME="parenttext" size=45>
   <INPUT TYPE="button" NAME="submit" VALUE="Send To Child" onclick="sendToChild()">
<INPUT TYPE="text" NAME="received" size=45>
   This text comes from the child.
   </FORM>
   


</BODY> </HTML></source>

Window Object Properties Array

   <source lang="javascript">

<HTML> <HEAD>

  <TITLE>Window Object Properties Array</TITLE>

</HEAD> <BODY> <SCRIPT> for (var i in window) {

 document.write ("Window property(" + i +  "): " +
    window[i] + "
");

} </SCRIPT> </BODY> </HTML></source>


Windows in Action

<p>The window object is one level higher than the document object in the JavaScript object hierarchy.

The window object can manipulate the current window as well as create new window instances.

If window B is created by window A, window B is considered a child of window A.



   <source lang="javascript">

<html>

   <body>
   <script language="JavaScript">
   
   </script>
   <form name="form1">
   <input type="button" value="Create Child" onClick="create()">
   </form>
   </body>
   </html></source>