471,310 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

View with or without frames - giving users the choice

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.h ref;
}
} // 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/Rob...osal/index.htm

Any help would be most appreciated!

Rob
:)
Jul 23 '05 #1
2 1493
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

Jul 23 '05 #2
Hi Kaeli,
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...


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
:)
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

40 posts views Thread by JohnnyCJohnny | last post: by
31 posts views Thread by wallster | last post: by
2 posts views Thread by Robert Stearns | last post: by
1 post views Thread by SteveComplex | last post: by
7 posts views Thread by rjames.clarke | last post: by
12 posts views Thread by MartinRinehart | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.