Load FrameSet

If a page containing the following script is loaded into a browser window it will load the parent frameset with the default pages.

<script type="text/javascript">
if (document.location == top.document.location) 
document.location = "frameset.htm" 
</script>

Where frameset.htm would be the name of your frameset page.

If you want a page only to be shown with its parent frameset then the following scripts will load the frameset and then load the page in its correct frame.

Example 1 - Using the frames name

Download example 1

In the frameset page:

<script type="text/javascript">
<!--
function LoadFrame(){
if (self.location.search){
parent.framename.location = location.search.substring(1,location.search.length)
}
}
onload = LoadFrame
// -->
</script>

<frameset cols="150,*" border="1">
<frame src="nav.htm" name="navbar">
<frame src="default.htm" name="main">
</frameset>

Where framename is the frame that the page is loaded into

The following is place in the head section of the page you want loaded into its frame.

<script type="text/javascript">
<!--
if (self == top){
var url = self.location;
self.location = "frameset.htm?" + url
}
// -->
</script>

Example 2 - Using the frames index number

Download example 2

Put the following script in the frameset page

<script type="text/javascript">
<!--

function loadFrame(){
if (location.search.length > 0){
frameInfo = unescape(location.search.substring(1)).split("&")
parent.frames[frameInfo[1]].location = frameInfo[0]
}
}
// -->
</script>

and add onload="loadFrame()" to the opening frameset tag.

In the page(s) loading into the frame put the following script

<script type="text/javascript">
<!--

if (top.location.href.indexOf("frameset.htm") == -1){
top.location.href = "frameset.htm?page.htm&n"
}

// -->
</script>

Where n is the index number of the frame

Example 3

The first script creates the frameset, the second script is placed in the page that checks if it is in the frameset, if it is not in the frameset it will load the frameset and itself into the frame that you state.

Download example

This script is set up for a three frame frameset but can be altered to suit any frameset design by adding or deleting a var frame? and its associated information.

var frame1, var frame2, and var frame3 identify which pages are loaded into it the frames when the frameset is loaded and also identifies that frame with a number "1". This number is also used in the second script.

Copy the frameset page changing the page path and name as necessary.

<HTML>
<HEAD>
<TITLE>FrameSet Page</TITLE>

<script type="text/javascript">
<!--
// The following pages are loaded by default
var frame1 = "page1.htm"; // page to be loaded into the Navbar frame
var frame2 = "page2.htm"; // page to be loaded into the Header frame
var frame3 = "page3.htm"; // page to be loaded into the Main frame
var str = location.search;
var pos = str.indexOf("&")
if (pos != -1) {
var num = str.substring(pos + 1, str.length);
window["frame" + num] = str.substring(1, pos)
}

document.write(
'<FRAMESET COLS="18%, *">',
'<FRAME SRC="', frame1, '" NAME="navbar">',
'<FRAMESET ROWS="75, *">',
'<FRAME SRC="', frame2, '" NAME="header">',
'<FRAME SRC="', frame3, '" NAME="main">',
'</FRAMESET>',
'</FRAMESET>'
)
// -->
</script>

</HEAD>

</HTML>

Copy the following into the <HEAD> section of the page that will check the parent frameset.

<script type="text/javascript">
<!--
if (top.location.href.indexOf("yourframeset.htm") == -1)
top.location.href = "yourframeset.htm?yourpage.htm&3"
// -->
</script>

The yourframeset.htm path is relative to yourpage.htm

The yourpage.htm is the name of actual page that this second script is in with the path being relative to yourframeset.htm

&3 is the frame that the page will be loaded into once the parent frameset has loaded.

Example:

The frameset for this page, (framfram.htm), resides in a folder called "main" whilst this page, (loader2.htm), resides in a folder called frames.

Example

Therefore.........

<script type="text/javascript">
<!--
if(top.location.href.indexOf("framfram.htm") == -1){
top.location.href = "../../main/framfram.htm?../webplus/frames/loader2.htm&3"
}
// -->
</script>

......would be the paths in the script.

If you now click on your page it will load the frameset and itself into the main frame.