Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Frame Manipulation

Status
Not open for further replies.

jlong07

Technical User
Nov 8, 2002
56
US
I am trying to get a link to bring up a frameset, but replace the default page for one of the frames with a different page. I have 3 frames (left, top, body). I want the left and top frames to display the default pages listed in the frameset, but I want the body to display a different page than the default one listed in the frameset. If I could get some help with how to code this. Thank you!
 
It sounds like you want to make links in the left or top frame open a new page in the main frame, right? Like this:

<a href=&quot;page.html&quot; target=&quot;main_frame_name&quot;>Open in Other Window</a>

Then make sure that you name the main frame what you use in the target of the links.

You can also make all links in the left or top frame open in the main frame by adding this to the <head> of the page with the links:
<base target=&quot;main_frame_name&quot;>

That way, you don't have to specify target=&quot;...&quot; in each link.

Rick -----------------------------------------------------------
 
Actually, I am trying to link change all three frames, but I want the page that displays in the main section of the frameset to be different than the one specified in the code for the frameset page. For instance, A Frameset has a default header, navigation, and main section. I want to open this frameset from a link outside of the frameset itself, but I want the page that opens in the main section to be different than the default start page. I hope that explains it a little better.
 
Ok. Do this:

<a href=&quot;page2.html&quot; target=&quot;other_frame_name&quot;>Open other</a>

Then make sure that the name of the frame is the name in the target of the link.

Rick -----------------------------------------------------------
 
If I understand you correctly, you want to link to the frameset page but pass it some kind of parameter to determine the content of one of the frames. So, for example, you get the title in one frame, the navbar in another and the page-of-your-choice in the third.

AFAIK there's no way of doing this in plain HTML - that's one of the reasons frames are frowned upon by many designers. I solved this problem by writing a Perl script that would dynamically build a frameset page containing the one I wanted. Then I saw the light and redesigned my site without frames :)

I could probably dig out that script if it would be useful. -- Chris Hunt
Extra Connections Ltd
 
The other way to do is to use JavaScript.

<SCRIPT language=&quot;JavaScript&quot;>
function ThreeFrames(url1,url2,url3){
top.frame1.location=url1;
top.frame2.location=url2;
top.frame3.location=url3;}
</SCRIPT>

Then call it such as:

<a href=&quot;javascript:ThreeFrames('test1.html','test2.html','test3.html')&quot;>Test Page</a>

What this will do is change the frames within a frameset, allowing you to change frames on the fly.

However, this is all fine as long as the frames are the same, but if another frameset page has a different layout, then you could use JavaScript to set the locations of the pages, or you could use Chris' Perl script.

A JavaScript example would be:

<a href=&quot;FrameSetPage.html?page1=test1.html&page2=test2.html&quot;>Test</a>

The FrameSetPage.html would have the following code:

<html>

<title>Test Page</title>

<SCRIPT language=&quot;JavaScript&quot;>

function GetParam(name)
{
var start=location.search.indexOf(&quot;?&quot;+name+&quot;=&quot;);
if (start<0) start=location.search.indexOf(&quot;&&quot;+name+&quot;=&quot;);
if (start<0) return '';
start += name.length+2;
var end=location.search.indexOf(&quot;&&quot;,start)-1;
if (end<0) end=location.search.length;
var result=location.search.substring(start,end);
var result='';
for(var i=start;i<=end;i++) {
var c=location.search.charAt(i);
result=result+(c=='+'?' ':c);
}
return unescape(result);
}
</SCRIPT>

<SCRIPT language=&quot;JavaScript&quot;>

var pg1 = GetParam('page1');
var pg2 = GetParam('page2');

document.write('<frameset rows=&quot;100,*&quot;>');
document.write('<frame name=&quot;title&quot; src=&quot;' + pg1 + '&quot;');
document.write('<frame name=&quot;main&quot; src=&quot;' + pg2 + '&quot;');

</SCRIPT>
</html>
 
Thanks guys, that is exactly what I am looking for. I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top