View with or without frames - giving users the choice

R

relaxedrob

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:

<script type="text/javascript" language="JavaScript">
<!--
function withFrames()
{
if (parent.frames.length == 0) {
parent.location.href='/RobertMarkBram/index.htm';
// parent.mainFrame.location.href=document.location.href;
}
} // end withFrames function
function withoutFrames()
{
if (parent.frames.length != 0) {
parent.location.href=document.location.href;
}
} // end withFrames function

document.write("<p onClick='withFrames();'>View with frames.</p>");
document.write("<p onClick='withoutFrames();'>View without
frames.</p>");

-->
</script>

My problem is to get the 'target' page loaded back into mainFrame..

You can see my attempt here:
http://phd.netcomp.monash.edu.au/RobertMarkBram/phd/proposal/index.htm

Any help would be most appreciated!

Rob
:)
 
K

kaeli

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/testFrameset.htm?url=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.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>

--
 
R

relaxedrob

Hi Kaeli,
You need a dynamic frameset.
This is best done server-side, but as long as you're already using
javascript...

Thank you very much for your suggestion. I started looking for a
solution using ASP serverside singe I agree with your suggestion.. but
in the end I have decided to avoid frames altogether and use
serverside templates. But thank you again for your time - it is much
appreciated!

Rob
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top