Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Making windows

Windows are one of the most important objects in JavaScript as they can hold vast amounts of information that the user can interact with. A window is thankfully not too difficult to construct, all that a developer needs to do is call the "open" method of the window object and pass it the parameters it requires.

The following example is going to create a "full blown" JavaScript window object that will have all possible features. An IMPORTANT NOTICE is written to the window after it is triggered by a button's onClick event. If the window is open and the user clicks the make window button again the window is not made again since it only needs to be made one time. Run Code | View Code

Process

Events

The user presses the button - onClick event of the "make window" button defined in the body of the document.

Input

Event Trigger

The onClick event of the "make window" button in the document will call the makeWindow function that shows the window.

The Solution

Define the button

Define the button in the body of the document and make it's onClick event call the makeWindow function <input type="button" value="Call Make Window function" onClick=" makeWindow()">

Define makeWindow

Function analyses

The makeWindow function first checks if the "open" method ever opened a window and placed the reference into "referenceToWindowObject ".

It does this by checking if the window is "null", if the window reference (referenceToWindowObject ) contains the window object it means the window is made. It will contain a reference to the window even if the window is closed. If the window was made it then proceeds to the second check, it checks if the window is closed by checking the "closed" property of the window.

If either of these conditions are "true" it means the window is not visible and not minimized so the window is made. Otherwise the window is positioned to the top of all other windows and is activated by using it's "focus()" method.

Then (If necessary) three sets of parameters are then declared as local variables for the window:

  1. url - A file
  2. targetName - Target name used to reference the window with the target attribute of a hyperlink or a form
  3. property list -A list of window features that set the look and feel of the window and it's behavior.

Once the parameters are set the window is created and made visible with the "open" method. The method is passed the url, tagetName and property list so the browser can hopefully render the window as specified.

The content is then written to the window's document.

Comments with code

function makeWindow(){
If the window is not made or it was closed make the iwndow if(referenceToWindowObject == null || referenceToWindowObject.closed){
The Conent of this window var url = '' used for targeting var targetName = "impotent_notice" Set up the window feature list, delimited by comma(,) var properties = do not show the menu bar "menubar=" + false + "," do not show the tool bar + "toolbar=" + false + "," do not show the location bar +"location=" + false + "," do not show the status bar + "status=" + false + "," Disallow the window to be reissued + "resizable=" + false + "," Width of the window + "width=" + 220 + "," Height of the window + "height=" + 196 + "," x position of the window for Internet Explorer + "screenX=" + 313 + "," x position of the window for Netscape Navigator + "left=" + 313 + "," y position of the window for Internet Explorer + "screenY=" + 197 + "," y position of the window for Netscape Navigator + "top=" + 197 Make the window with the three sets of required parameters. When the window is made a reference of it is inserted into referenceToWindowObject referenceToWindowObject = pen(url,targetName,properties) Use the window reference to write the message to it's document wrapped in a <H1> tag referenceToWindowObject.document.write(" <H1> IMPOTENT NOTICE! </H1>");
This window is visible maybe minimized and Not closed }else{
Give the focus to the window by using it's focus method referenceToWindowObject.focus() }
}

Importent

Run Code | View Code

See also: Using prompt | Using alert | Using confirm


Using alert | Using the status bar | Changing the background color of the document | Changing the content of a document | Using prompt | Using confirm | Changing the URL of a window Manually | Querying a text field's value | Checking the selected value of a select object | Checking if a checkbox is selected | Checking if a radio button is selected in a group | Making a rollover | Preloading images | Getting the time | Using setTimeout/setInterval | Making cookies

JavaScript Tutorial Home