Usage
There is one required file: frameset.js. Include it in the head element on
the page that has the frameset element like this:
<script src="frameset.js" type="text/javascript"></script>
It is important that this script be located before the opening frameset tag.
For the sake of clarity, this example will use a two-frame frameset document,
like this:
<html>
<head>
<script src="frameset.js"
type="text/javascript"></script>
</head>
<frameset cols="300,*">
<frame name="contents" target="main"
src="framed_contents.htm">
<frame name="main" src="framed_page_1.htm">
</frameset>
</html>
There are two frames; one is named "contents" and the other, "main." You may
name the frames anything you like. The frame named "main" will be the frame that
is controlled by the FrameSetNav object, since it has the main content of our
Web site, and will be changing the most.
Inside the head element of the frameset page, initialize the FrameSetNav
object with the name of the main frame, like this:
<script type="text/javascript">
FrameSetNav ("main");
</script>
At this point, the frameset web page is finished, and ready to use.
The methods of the FrameSetNav object are attached to the frameset window
(also called the top window). Instead of getting a reference to the FrameSetNav
object, simply call the methods that are attached to the top window, as shown
below.
To use the new frameset page, you need to be able to get specially modified
URIs to your web pages. Although you could determine these manually, it is far
simpler to use the GetNavURI method of the FrameSetNav object.
In our example, we have the web page framed_page_1.htm as the first page that
is displayed inside the frameset page. Suppose that we want to send a link in
email that, when clicked, will instead open framed_page_2.htm inside the
frameset page. To do this, edit framed_page_2.htm, and insert a call to the
method GetNavURI, like this:
<script type="text/javascript">
var sLink = window.top.GetNavURI(window);
</script>
Notice that the GetNavURI method is attached to the topmost window, which is
the window that contains the FrameSetNav object. The GetNavURI returns a URI to
the current page, which you can then save to your Favorites list (also called
bookmarking), or send in an email to anyone else that can see that web page. To
show this URI as a link on the page, use something like this:
<script type="text/javascript">
var sLink = window.top.GetNavURI(window);
document.write("<a href='" + sLink + "' target='_top'>");
document.write(sLink);
document.write("</a>");
</script>
Alternately, with the GoToNavURI method, you can update the browser so that
its Address Bar shows the current page in the main frame, like this:
<a href="javascript:window.top.GoToNavURI(window);">
Get link to this page in the Address Bar
</a>
Clicking on this hyperlink will reload the entire frameset, showing the
current page in the "main" frame.
|