|
|
|
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
<input type="button" value="Call Make Window function" onClick=" makeWindow()">
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:
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.
function makeWindow(){
if(referenceToWindowObject == null || referenceToWindowObject.closed){
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>");
}else{
referenceToWindowObject.focus()
}
}
The feature list is one messy but absolutely necessary string that contains boolean values to show or hide the window's bars and make the window reusable as will as numeric values that specify the size and position of the window. There are features that I am not even going to consider because they require you to get a security certificate that cost money. However the features that are here are explained below:
One must note the way of positioning a window in Netscape Navigator and Internet Explorer are different To position the left position of the window in Internet Explorer you use "screenX" but in Netscape Navigator you use "left" and to position the top you use "screenY" in Internet Explorer and "top" Netscape Navigator. Not making an already made window. In the above example the window is not made when the window is already made. If it were made again it would waste valuable resources including, processor time, page request time and additional request to the web server.
The window could be placed in the center of the screen by using offsetHeight and offsetWidth in Internet Explorer and innerWidth and
innerHeight in Netscape Navigator.
But the shortcut xScreen is much more efficient.
See xLayer Javascript objects at jscrambler.netfirms.com for more information about xScreen.
See also: Using prompt | Using alert | Using confirm