HTML and CSS Reference
In-Depth Information
EXAMPLE
10.7 (
CONTINUED
)
<h3>Click here to see through my winter window<br />
3
<a href="JavaScript:newWindow()">Winter Scene</a></h3>
</body>
</html>
EXPLANATION
1
The JavaScript function
newWindow
is defined.
2
The
open
method is called and returns a
window
object that is assigned to the vari-
able,
winObj
. The first argument to the
open
method is the URL of the new win-
dow; in this case the document is an image file called
winter.jpg
located in the cur-
rent directory. The name to be associated with this window is
winter
.
3
When the user clicks on the line
Winter Scene
, the JavaScript user-defined func-
tion,
newWindow
, is called (see Figure 10.16). This function is responsible for
opening the new window. Instead of a URL, the HTML <
a href
> tag is assigned
name of a JavaScript function. The
JavaScript:
label allows the function to be
called when the user clicks the link. Without the
JavaScript:
label, the browser will
try to find a URL address called
newWindow()
and fail.
Figure 10.16
A new popup window showing a winter scene is opened.