JavaScript Windows Object Properties Part II
In this JavaScript tutorial, you will learn about screenX, screenY, screenLeft and screenTop, top, length, frames, opener, parent and window property of Window object along with syntax and examples.
screenX:
This property screenX returns the x coordinate of the window relative to the user’s monitor screen. In other words this property namely ScreenX indicates in pixels the distance that the new window is placed from the left side of the screen horizontally. This property is a read onlywrite property.
General syntax for using this screenY property of Window object is as follows:
window.screenX
screenY:
This property screenY returns the y coordinate of the window relative to the user’s monitor screen. In other words this property namely ScreenY indicates in pixels the distance that the new window is placed from the left side of the screen vertically. This property is a read only property.
General syntax for using this screenY property of Window object is as follows:
window.screenY
screenLeft and screenTop:
These are read only properties and these properties returns the pixel position of the main window relative to top-left corner of the screen.
General syntax for using this screenLeft and screenTop property of Window object is as follows:
window.screenLeft
window.screenTop
Let us see an example to illustrate the use of the above screenLeft and screenTop properties of Window object.
|
In the above example the function Getcoordinate() displays the Left and Top coordinate of the Screen using the window.screenLeft and window.screenTop properties in it respectively.
top:
The top property is different from screenTop property. The top property returns the topmost ancestor window in other words returns a reference to the parent window.
General syntax for using the top property of Window object is as follows:
window.top
length:
This property is used to set or return the number of frames contained in a window. The length property of a Window Object returns the number of child frames contained within a window. The result returned by the length property of a Window Object has the same result when using the length property of the frames array.
General syntax of length property of Window Object:
window.length
frames:
The frames property references all the named child frames in the current window by representing in an array. The frame property of a window object is an array containing window objects. In this array, each one refers to the content of a frame within the window, meaning that each one refers to a separate frame.
NOTE: Every window refers to a frames array, which contains a list of frames within that window. Each frame contains a different window. The document.frames property is different from the window.frames property and rarely used in JavaScript.
General syntax of frames property of Window Object:
window.frames ( = "frameID")
The frameID in the above is optional. The references are stored in the array in the order that they are defined in the source code. If a programmer wishes to access items in the array, the frameID can be used. The frameID can be the framename defined with the <FRAME> tag in the HTML source. This is given as a String representation and can also be represented as an integer. If a programmer wishes to represent the frameID as an integer, note that ‘0’ is always the first element in the array.
To access the elements, the programmer can represent as follows:
window.frames[0]
window.frames[1]
or as
window.frames["Exforsys"]
It is also possible to count the number of child frames contained within a window by combining the frames property with the length property as window.frames.length property.
opener:
A window is opened using window.open. From the destination window, if the programmer wishes to return details of the source window, the opener property of the window object can be used. The opener property returns a reference to the window that created the window.
General syntax of opener property of Window Object:
window.opener
A new window has a reference to the window that opened it stored in the opener property. The opener property is applicable only on the topmost window object of the new window.
An example to understand the opener property of window object:
|
The output of the above example is
true
The new window named exfWin is opened and then the opener property of this exfWin window is tested against the window object. This returns true since the window that opened the exfWin was the current window.
parent:
The parent property of a window object returns the parent window. The parent property references the window that contains the calling child frame.
General syntax of parent property of Window Object:
window.parent
In the top level of windows, the parent property is the same as the self property of window object.
An example to understand the parent property of a window object:
|
The output of above program is a button with message
Click to see the Output
When this button is clicked, the output displayed is:
Parent name of Window is: Exforsys
window:
The window property of a window object is used to refer to the current window. The window property is another name for the self property.
General syntax of window property of Window Object:
window.window
Since the self property of window object is the same as window property of a window object, it is very clear that all the following representations are the same:
window.self
window.window
self.self
self.window.self