HTML and CSS Reference
In-Depth Information
EXAMPLE 10.19 ( CONTINUED )
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
var myUrl;
1
function openSite( url ){
2
parent.main.location = url;
3
myUrl=url;
}
4
function collapse(){
if ( ! myUrl){
5
parent.location = "tocmain.html";}
else{
6
parent.location=myUrl;
// Force this page into the
// parent location
}
}
</script>
</head>
<body bgcolor="#FFFFFF">
7 <p><a href="JavaScript:openSite('tocmain.html')">Home</a><p>
<p><a href="JavaScript:openSite('http://ellieq.com');">
Page 1</a></p>
<p><a href="JavaScript:openSite('http://prenticehall.com');">
Page 2</a></p>
<p><a href="JavaScript:openSite('http://google.com');">
Page 3</a></p>
8 <p><a href="JavaScript:collapse();">Hide Menu</a><p>
</body>
</html>
EXPLANATION
1
A function called openSite is defined. It takes one parameter, the URL of the Web site.
2
The parent is the main window where the frames are defined. main.location is the
frame on the right side of the toolbar. It was named main when the framesets were
defined. The main frame is assigned the URL of one of the Web sites after the user
clicks a link in the menu bar.
3
The global variable myUrl gets the URL of the current Web site shown in the right
frame.
4
The function called collapse() is defined. Its function is to make the right frame
fit into the whole window, hiding the menu bar.
5
If the user hasn't selected any page prior to selecting Hide Menu, the main frame
will take up the whole window. The location property of the window object refers
to the location of the parent window, the main window from where the frames
were created.
Continues
Search WWH ::




Custom Search