<%@ Page Language="C#" Debug="true"%> Code Samples-Frames
Microsoft Office FrontPage 2003      
Developer's Toolkit
Resources | Links | Search
  extend design code  
             
  New Features
 
Microsoft® Windows® SharePoint Services
 
Microsoft® Office SharePoint Portal Server
 
Microsoft Office System
 
.NET Framework
 
 
Real world scenarios that fully expose great new functionality in FrontPage 2003 and Windows SharePoint Services.
 
 
  financial planning finance  
  sales & marketing sales & marketing  
  human resources human resources  
   
  FrontPage Customization Kit > Resources > Code Library

Frames Documentation

Contents

Example page

Download this sample

 

Summary

One of the major disadvantages of using frames on your Web site is that there is no built-in way to send or save a link to a specific page that is displayed in a frame; instead, either the link to the main frameset page is displayed in the Address Bar (which always displays the same pages when it is first loaded), or a link to a page within a frames page does not automatically load the frames page. This sample overcomes this shortcoming, and makes it possible to send or save a link (shortcut) to a specific page within a frames page.

The Frame Browser object is created in javascript with the FrameSetNav object. The most important part of making this object work is simply creating it in the frameset page. The GetNavURI and GoToNavURI methods are the two most important methods to call; typically, you will call only one.
 

 

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.
 

 

Reference

There is only one object for this feature. The FrameSetNav object provides all of the functionality required.

FrameSetNav object
Properties

There are no public properties for this object.

Methods
Method Parameter Description
FromNavURI   Returns a boolean indicating whether the page currently displayed in the main frame was loaded by the FrameSetNav object, or whether it was either the default page loaded by the frameset or a page loaded from another link. If FromNavURI returns true, then the page was loaded by the FrameSetNav object (or at least, would be loaded by the current URI in the Address Bar of the browser). If FromNavURI returns false, then the page is either the default page for the frame in the frameset, or the page was loaded from another link.
  framedWindow Reference to the window object of the current document.
GetNavURI   Returns a string with the URI that can be used as a shortcut or link to display the current page inside the frameset page.
  framedWindow Reference to the window object of the current document.
GoToNavURI   Causes the browser to reload the current frameset using the current document rather than the default document for the frameset.
  framedWindow Reference to the window object of the current document.

 

 

Remarks

Although URI arguments are preserved by the FrameSetNav object and passed through to the framed web page, form POSTed fields are not. When using POST to submit data, do not attempt to post it to the URI returned by GetNavURI (or GoToNavURI), unless your server-side code for the frameset page is ready to accept POSTed fields.

You may capture the URIs generated by the GetNavURI method and use them in hyperlinks in your web site. However, if you do, remember to always set the target window for the hyperlink to the top window (also called the Whole Page target frame).
 

 

Customization

The FrameSetNav object handles URI arguments (parameters and arguments in the URI that follow the question mark "?") but it does not handle URI fragments (the part of the URI following the hash, or pound sign "#"). Modify the FrameSetNav, FrameSetPageLoader, and FrameSetNav_GetNavURI methods in frameset.js to capture and pass through the URI fragment. The find the URI fragment for the current window, use the window.location.hash property.


^ Back to top