Welcome to WebmasterWorld Guest from 3.80.4.76

Forum Moderators: open

Message Too Old, No Replies

Targeting two iframes with one link

can I target two or more iframes with one link

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:15
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


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]

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:15
votes: 0


Sorry for being a dolt but is the javascript necessary or does the html code work by itself?
6:57 pm on Sept 15, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


I do not know of a way to do it without javascript. Maybe someone else will come by who does know of a way. :)
7:27 pm on Sept 15, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 15, 2003
posts:4
votes: 0


should this work, i mean...is this tested? cuz i don't seem to get it right...:s
7:38 pm on Sept 15, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


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

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

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:15
votes: 0


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?
8:03 pm on Sept 15, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 15, 2003
posts:4
votes: 0


should that last one work? :s is that tested?
8:14 pm on Sept 15, 2003 (gmt 0)

New User

10+ Year Member

joined:Sept 15, 2003
posts:15
votes: 0


where should the javascript code be placed?
11:26 pm on Sept 15, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


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>

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:15
votes: 0


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...

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

New User

10+ Year Member

joined:Sept 15, 2003
posts:4
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members