HTML and CSS Reference
In-Depth Information
EXPLANATION
1
The function
newWindow()
is defined.
2
The
open()
method is passed the URL of the JPEG image file that will be displayed
in the new window called
winter
. The width and height of the new window are
1150 and 350 pixels, respectively. The window is resizable and has scrollbars. A
location box appears in the top of the new window. The name of the
window
ob-
ject created by the open method is
winObj
. It is important that you do not use any
spaces or linebreaks between the commas in the list of parameters.
3
The
focus()
method brings the new window into focus: It appears in front of the
parent window or any other windows.
4
The
blur()
method (commented out) would push the window behind any other
windows that are open.
5
The user-defined function,
closeWindow()
, is defined.
6
The reference to the
window
object,
winObj
, will call the
close()
method to close
the new window that was opened.
7
The
newWindow
function is called when the user clicks the link
Winter Scene
. The
label,
JavaScript:
, prevents the link from trying to activate a URL, and instead goes to
the JavaScript program and calls the function
closeWindow()
. See Figure 10.17.
8
When the user clicks this link, the new window will be closed. The original or
parent window will remain in the browser. If the name of the new
window
object
is not provided, the
close()
method will try to close the parent window.
Figure 10.17
Opening a new resizable window with a scrollbar and size dimensions in
pixels: Output from Example 10.8.