11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Opening and Closing Generic Windows<br />

While the alert(), confirm(), and prompt() methods create specialized windows quickly, it is<br />

often desirable to open arbitrary windows to show a Web page or the result of some calculation.<br />

<strong>The</strong> Window object methods open() and close() are used to create and destroy a window,<br />

respectively.<br />

When you open a window, you can set its URL, name, size, buttons, and other attributes, such<br />

as whether or not the window can be resized. <strong>The</strong> basic syntax of this method is<br />

window.open(url, name, features, replace)<br />

where<br />

url is a URL that indicates the document to load into the window.<br />

name is the name for the window (which is useful for referencing later on using the<br />

target attribute of HTML links).<br />

features is a comma-delimited string that lists the features of the window.<br />

replace is an optional Boolean value (true or false) that indicates if the URL specified<br />

should replace the window‘s contents or not. This would apply to a window that was<br />

already created.<br />

An example of this method is<br />

secondwindow = open("http://www.yahoo.com", "yahoo",<br />

"height=300,width=200,<br />

scrollbars=<br />

This would open a window to Yahoo with height 300 pixels, width 200 pixels, and scrollbars, as<br />

shown here:<br />

<strong>The</strong>re are a variety of ways programmers create windows, but often links or buttons are used.<br />

For example:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!