Forum Moderators: open

Message Too Old, No Replies

Targeting two iframes with one link

can I target two or more iframes with one link

         

Blade Runner

6:44 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



After learning how to use iframes, I want to be able to target more than one named iframe with a link.

Example: A link on a navbar points to iframe "nav" currently. But I also want that link to point to "nav" and "content". Is this possible? If not, what are some workarounds?

korkus2000

6:51 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the board Blade Runner,

Try this, I believe it will do the trick:

function twoFrameChange(nav,content){
top.iframe1.location.href = nav;
top.iframe2.location.href = content;
}

<a href="javascript:twoFrameChange('nav.htm','content.htm');">link1</a>

<edit>fixed script</edit>

[edited by: korkus2000 at 7:42 pm (utc) on Sep. 15, 2003]

Blade Runner

6:56 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



Sorry for being a dolt but is the javascript necessary or does the html code work by itself?

korkus2000

6:57 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do not know of a way to do it without javascript. Maybe someone else will come by who does know of a way. :)

eleven

7:27 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



should this work, i mean...is this tested? cuz i don't seem to get it right...:s

korkus2000

7:38 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry about that. Should have tested it. try this function:

function twoFrameChange(nav,content){
top.iframe1.location.href = nav;
top.iframe2.location.href = content;
}

Blade Runner

8:02 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



I tried the code but I'm getting "error on page". Are the javascript targets supposed to be *.htm pages named "nav" and "content"? Would it change things if the javascript and the href pointed to different names?

eleven

8:03 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



should that last one work? :s is that tested?

Blade Runner

8:14 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



where should the javascript code be placed?

korkus2000

11:26 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to change the file paths here to your paths. These paths are just examples:

<a href="javascript:twoFrameChange('nav.htm','content.htm');">

you need to change the frame names to the names of your frames here:

top.iframe1.location.href = nav;
top.iframe2.location.href = content;

The javascript function should go inside the head tag inside a script tag.

What is happening when you run it eleven? Works in Opera and IE here.

korkus2000

11:35 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the test page that works for me:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>two frame test</title>
<script>
function twoFrameChange(nav,content){
top.iframe1.location.href = nav;
top.iframe2.location.href = content;
}
</script>
</head>
<body>
<iframe name="iframe1" src="http://www.yahoo.com"></iframe>
<iframe name="iframe2" src="http://www.google.com"></iframe>
<br>
<br>
<a href="javascript:twoFrameChange('http://www.msn.com','http://www.alltheweb.com');">link1</a>
</body>
</html>

Blade Runner

12:40 am on Sep 16, 2003 (gmt 0)

10+ Year Member



It works quite well now, thank you very much!

The main reason I wanted the targetting to go to two iframes is that I ran into a design flaw with my site in that the first frame has navigational links in it EXCEPT the homepages iframe. DOH! Now, with both the nav and content frame showing material, I can put updates on the content frames html page and keep the homepage "banner" in the nav iframe the same.

Life is good...

eleven

4:46 pm on Sep 16, 2003 (gmt 0)

10+ Year Member



it works perfectly now, thx guys, ow you one!