SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Frame Master : Static Solution

The most simple solution is to add a small script that tests whether the document is within its frameset:

  // Name of frameset file
  var container = "demo.htm" 
  // Disect the path of the parent
  var wname = parent.location.pathname.substring((parent.location.pathname.lastIndexOf("/"))+1).toLowerCase()
  // Test whether inside that document
  if (wname!=container)
    parent.location.replace(container)

The above code just checks whether the frameset exists. However, it does nothing to prevent your frameset and documents from appearing within another frameset. To always make sure your document is not only in the frameset, but the frameset is the top-most frame, change the parent reference to a refernece to the top:

  var container = "demo.htm"
  var wname = top.location.pathname.substring((top.location.pathname.lastIndexOf("/"))+1).toLowerCase()
  if (wname!=container)
    top.location.replace(container)

The above two solutions work if the frameset document is already defined containing the current document. For example, the above code works assuming the top-most frameset was defined similar to the following and the document with the code was named page1.htm or menu.htm:

  <FRAMESET ROWS="*,*">
    <FRAME SRC="menu.htm">
    <FRAME SRC="page1.htm">
  </FRAMESET>

If the user enters page 1 outside of the frameset, it is properly loaded. However, if the user enters a different page (eg., page2.htm) that is expecting to be linked and contained within the above frameset, the redirection would not work properly. Instead of seeing page 2 inside the frameset, they would see page 1. Next, we dynamically generate the frameset document to allow it to automatically contain any document.