The Window Phase of Chrys`s Approach to ACP
(Page 1 of 4 )
The Window Phase of Chrys’s Approach to ACP is similar to the Document Phase. However, instead of having HTML documents (pages) opened within one browser window, you open both browser windows. This is the ninth part of a twelve-part series on Active Client Pages.
Each of the windows opened in the Window Phase can have documents of the document phase of Chrys's Approach. As you can see, this approach incorporates the document phase of Chrys's Approach, the script approach and the Ajax approach.
Window Object
The Window object is the top-level object in the JavaScript hierarchy. The Window object represents a browser window. A Window object is created automatically with every instance of a <body> or <frameset> tag. However, we do not use frameset in this phase.
Window Object Properties we need
Property | Description |
closed | Returns whether or not a window has been closed. |
defaultStatus | Sets or returns the default text in the status bar of the window. |
name | Sets or returns the name of the window. |
opener | Returns a reference to the window that created the window. |
self | Returns a reference to the current window. |
status | Sets the text in the status bar of a window. |
top | Returns the topmost ancestor window. |
Window Object Methods we need
Method | Description |
blur() | Removes focus from the current window. |
focus() | Sets focus to the current window. |
open() | Opens a new browser window. |
close() | Closes the current window. |
There is more to the open() method than what I have stated. We saw a bit of the extra features in the previous part of the series. Let us look at the syntax and parameter in more detail.
The Window open() Method
Definition and Usage
The open() method is used to open a new browser window.
Syntax
window.open(URL,name,specs,replace)
Parameter | Description |
URL | Optional. Specifies the URL of the page to open. If no URL is specified, a new window with about:blank is opened. |
name | Optional. Specifies the target attribute or the name of the window. The following values are supported: _blank - URL is loaded into a new window. This is the default. _parent - URL is loaded into the parent frame. _self - URL replaces the current page. _top - URL replaces any framesets that may be loaded. name - The name of the window.
|
specs | Optional. A comma-separated list of items. The following values are supported: 
|
replace | Optional. Specifies whether the URL creates a new entry or replaces the current entry in the history list. The following values are supported:
|
Window open() Method Example
The following example opens an about:blank page in a new browser window:
<html>
<body>
<script type = "text/javascript">
myWindow = window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
</script>
</body>
</html>
The second statement in the script opens the window. The expression to the right hand side of the assignment operator returns a reference. This reference is held by the myWindow variable, and used to write content to the opened window. As we see in the last statement in the script, this reference can take the document property, which can take the write() method.
Note: the window object does not have the write() method. It is the document object that has the write() method. We have to distinguish between the window open() method and the document open() method which we have seen before in this series.
The document open() method opens an output stream which can result into a document. A document is a page in the browser window. A window is the browser window itself.
Just after using the document open() method, you can use the document write() method to write HTML contents to the output stream. You then use the document close() method to close the output stream, thereby creating a newly-opened document, which would be in the same browser window as the previous document (page).
On the other hand, the window open() method opens a new browser window, with its own bars (title, menu and tool bars), separated from the previous window -- and that is it; you do not have to close this opening process. However, you can use the reference to the opened window (for example, myWindow in the above case); you can write to it. The window object has a close() method, but, this method does not close the opening process; it removes the window from the screen.
You can try the above example; save it as an HTML file and then open it.
Next: Examples of Window Properties and Methods >>
More JavaScript Articles
More By Chrysanthus Forcha