In article <fa**************************@posting.google.com >,
re********@optusnet.com.au enlightened us with...
Hi All!
I have a frameset document and I want each mainFrame document to have
the following ability:
- be viewed by itself (i.e. without frames if within frameset).
- be viewed within frame (i.e. put back in the frameset if not within
frameset).
I have written the following so far:
You need a dynamic frameset.
This is best done server-side, but as long as you're already using
javascript...
This is the one I wrote that has two frames. Watch for word-wrap and put
your doc names in the sources and change the frame names and attributes
as desired. You pass the url to the frameset.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"
"http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>Test Javascript Dynamic Frameset</title>
<script language="javascript" type="text/javascript">
function loadMainFrame()
{
/* See if the url has a doc to load and load it if present.
The page to load is expected to be in the param "url" as in
http://www.servername.com/testFrames...testFrame3.htm.
If the param is absent, nothing is changed, which will keep the
default page in the mainFrame.
*/
var searchString = window.location.search.substring(1);
if (searchString == null || searchString.length == 0) return; // if
no params specified, do nothing
var pairs = searchString.split('&'); // allows more params than just
the url for extensibility
if (pairs == null) return; // if no params specified, do nothing
// pairs has the pairs of values, like url=whatever.htm, param2
=value2, param3=value3
// we split that up by the = sign into an associative array (hash)
for easy lookup
var tmp;
var paramArray = new Array();
for (var i=0; i<pairs.length; i++)
{
tmp = pairs[i].split("=");
paramArray[tmp[0]] = tmp[1];
}
// paramArray should now have values like paramArray["url"]
=whatever.htm, paramArray["param2"]=value2
if (!paramArray["url"]) return; // if no url specified, do nothing
else window.frames["mainFrame"].location.href=paramArray["url"];
return;
}
</script>
</head>
<frameset cols="110,*" onLoad="loadMainFrame()">
<frame src="testFrame1.htm" name="leftFrame">
<frame src="testFrame2.htm" name="mainFrame">
</frameset>
</html>
--
--
~kaeli~
Suicide is the most sincere form of self-criticism.
http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace