ASP Net Center.com
JavaScript
Introduction
Variables & Arrays
Functions
If Statements
Case Statements
Loop Statements
Alert
Form Processing
Date Objects
Window Objects

Javascript Pop-up Window Objects

The javascript pop-up window object refers to the web browser, and all of the items you can see within it. This tutorial will explain how objects are used to create a pop-up window, and the various properties and methods available. Properties are sub-objects which are a part of another object. Methods are the different ways you can do things. Javascript pop-up window object properties refer to: window name, window size, window address, etc. Javascript pop-up window object methods refer to: open, close, scroll, move, resize, alert, etc.
 
You need to at least specify for a blank window to open. Here is how you open a blank window: window.open()
(This will open a blank window, and use all of the default settings).
 
The best way to display a window with a particular: size, color, menu, toolbar, object, etc. is to create a function, and call it when either: a link is clicked, when an object is clicked, or for an onload event.
 
Below is a pop-up window that displays another website in a smaller window:
 
<html>
<head>
<script type="text/javascript">
function WindowE()
{
window.open("http://www.videogamedeals.com", "WinE", "width=650,height=500,toolbar=no,resizable=yes")
}
</script>
</head>
<body>
<a href="javascript:WindowE()">Click Here</a>
</body>
</html>

Free ASP Scripts
Click Here!

 
 
We created a pop-up window with a width of 650 pixels wide, and a height of 500 pixels high. It displays the website: VideoGameDeals.com. The name of the window is 'WinE', and it is resizable because we set that option to 'yes', however it won't display the toolbar because we set that option to 'no'. This window has been created using a function. When this webpage loads, all you will see is the 'Click Here' link (which calls the function that creates the window). Here is the result: Click Here.

 
When creating a javascript pop-up window, remember the following syntax: window.open("url", "windowName", "windowAttributes").
 
URL > specifies the domain name for a website.
WindowName > refers to the name of the javascript window object.
WindowAttributes > are the various options such as: toolbar, statusbar, scrollbars, etc.
 
Here are a list of attributes for your pop-up window:
width height toolbar
location directories status
scrollbars resizable menubar

 
Below is a pop-up window that uses all of the various attributes listed above:
 
<html>
<head>
<script type="text/javascript">
function WindowC()
{
window.open("http://www.videogamedeals.com", "WinC", "width=550,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=no,resizable=yes,copyhistory=no")
}
</script>
</head>
<body>
<form>
<input type="button" value="Open Window" onclick="WindowC()">
</form>
</body>
</html>

Cheap ASP Hosting
Click Here!

 
 
This pop-up window displays the website: VideoGameDeals.com again, and sets all of the attributes to no (which means that this window will not display any of those named attributes). Also, we are using a button to call the function that creates the window. Below is the result (Click-on this gray rectangular button):

 
Below is a complete list of Properties and Methods available for javascript pop-up window objects:
 
Property Description Syntax
ClosedReturns boolean value to determine if a window has been closedwindow.closed
defaultStatusDefines the default message displayed in a window's statusbarwindow.defaultStatus(="message")
documentDefines the document to be displayed in a windowwindow.document
framesReturns an array containing references to all the named child frames in the current windowwindow.frames(="frameId")
historyReturns the history list of visited URLswindow.history
innerHeightReturns the height of a window's display areawindow.innerHeight = value
innerWidthReturns the width of a window's display areawindow.innerWidth = value
lengthReturns the number of frames in a windowwindow.length
locationThe URL of a website loaded into a windowwindow.location
locationbarA window's location bar (the property is visible)window.locationbar.visible=false
menubarA window's menu bar (the property is visible)window.menubar.visible=false
nameUsed to set, or return a window's namewindow.name
openerThe name of a window opened in a current windowwindow.opener
outerHeightUsed to return the height of the outer area of a windowwindow.outerHeight
outerWidthUsed to return the width of the outer area of a windowwindow.outerWidth
pageXOffsetUsed to return the X-coordinate of a current windowwindow.pageXOffset
pageYOffsetUsed to return the Y-coordinate of a current windowwindow.pageYOffset
parentThe name of a window containing a particular windowwindow.parent
personalbarReturns boolean value indicating the visibility of the directories barwindow.personalbar.visible=false
scrollbarsReturns boolean value indicating the visibility of the scrollbars barwindow.scrollbars.visible=false
selfUsed to refer to current windowself.method
statusThe message displayed in a window's status barwindow.method="message"
statusbarReturns boolean value indicating visibility of the status barwindow.statusbar.visible=false
toolbarReturns boolean value indicating visibility of the tool barwindow.toolbar.visible=false
topUsed to return the name of top-most windowwindow.top
windowUsed to return the current windowwindow.[property]or[method]
Method Description Syntax
alert(message)Displays a text string on a dialog boxalert("Type message here")
back()Loads previous page in the windowwindow.back()
blur()Removes the focus from a windowwindow.blur()
captureEvents()Sets a window to capture all events of a specified typewindow.captureEvent(eventType)
clearTimeout()Clears a timeout (set with the setTimeout method)window.clearTimeout(timeoutID)
close()Used to close a windowwindow.close()
confirm(message)Displays a confirmation dialog box with a text message confirm("type message here")
disableExternalCapture/
enableExternalCapture
Disables/Enables external event capturingwindow.disableExternalCapture( )/
window.enableExternalCapture( )
focus()Used to give focus to a windowwindow.focus()
forward()Loads the next page in a windowwindow.forward()
handleEvent(event)Invokes the event handler for a specified eventwindow.handleEvent(eventID)
moveBy(horizontal, vertical)Moves a window by the amount specified in the horizontal and vertical directionswindow.moveBy(HorValue, VerValue)
moveTo(x, y)This method moves the window's left edge and top edge to the specified x and y coordinatesmoveTo(Xposition,Yposition)
open()Used to open a windowwindow.open(url, name, attributes)
print()Displays a print dialog boxwindow.print()
prompt(message, defaultValue)Displays a prompt dialog boxwindow.prompt("Type message here", value)
releaseEvents(event)Release any captured events of a specified typewindow.releaseEvents(eventType)
resizeBy(horizontal, vertical)Resizes a window by the specified horizontal and vertical amountswindow.resizeBy(HorValue, VerValue)
resizeTo(width, height)Resizes a window to the specified width and height amountswindow.resizeTo(widthValue,heightValue)
scroll(x, y)Scrolls the window to the specified coordinateswindow.scroll(xValue, yValue)
scrollBy(x, y)Scrolls the window's content area by the specified coordinateswindow.scrollBy(HorValue, VerValue)
scrollTo(x, y)Scrolls the window's content area to the specified coordinateswindow.scrollTo(xValue, yValue)
setInterval(expression, time)Evaluates an expression in millisecondswindow.setIntervals(expression, milliseconds)
stop()Used to stop a window from loadingwindow.stop()

String, Date, & Array objects Home