• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Frames, Frames, and More Frames > Forcing a Page into a Frame

Forcing a Page into a Frame

When a search engine catalogs one of your pages, it doesn't know that the page is part of a frame. When a user finds your page via the search engine, clicking on the link will show just the single page, not the full frameset as you designed it. Script 4.4 shows you how to force the full frameset to display even though Google or another search engine doesn't know about the frameset. Figure 4.4 shows the page looking out-of-place, and Figure 4.5 shows it at home, snug in its frame. Scripts 4.2 and 4.3 show the frameset and the left navigation bar, respectively.

Figure 4.4. A lonely page, stranded by itself.


Figure 4.5. Your page, happily reunited with its parent and sibling.


To force a page into a frame:

1.
								if (top.location == self.location) {
							



Check to see if the current page (self) is at the top-most level. If it isn't, you're in a frameset.

2.
self.location.replace("frameset2.html")



If the location of the current page is at the top, then replace the current page with the URL of the frameset. This will then display your framed site as you designed it.

Script 4.2. Here's the frameset that should be loading your page.


Script 4.3. The left-hand navigation bar of the frameset.


Script 4.4. Use JavaScript to force your page into the frameset.


Tip

This method works fine if you only have a few pages that might be called from outside their frame, because it requires a separate frameset page for every page that you might want loaded (in this example) into the content frame. The next example shows a way to handle a large site.


  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint