View Full Version : Targeting two IFrames with one link

05-26-2008, 08:46 AM
Please forgive me if any of this doesn't make sense - I haven't been using JavaScript for very long!

I'm using two IFrames here, "a" and "back". I'm using the following code to target both the frames with a link in "a"

function changeLink(link1,link2) {

<a href="javascript:changeLink('samplepic.htm', 'back.htm')">

I'm trying to manipulate it so that, from a link in "back", "a" goes back one page in its history, while "back" displays another page. No surprises, I can't get anything to work. Any thoughts - if this is even possible at all? Thanks in advance!

05-26-2008, 02:26 PM
Where's 'blank'? Um, using the javascript history is sometimes unreliable across browsers. I think it might be particularly so here, as many browsers see the history stack as a property of the top page, so that whatever the last page change was, whether it occurred in an iframe or not is top of the stack.

You are not showing us your iframes. They should be named whatever you are trying to reference them as (often the mistake is made of giving them an id, but not an identifying name). So the should be like, for example:

<iframe name="back" . . . ></iframe>

The use of eval is almost always unnecessary and a bad idea. Iframes should be referenced (if you are going to get at them as objects of the parent) as part of the parent's frames collection.

However, If your link is in one of the iframes, it will change that iframe automatically, as long as it isn't targeted, but if targeted, it should change the targeted iframe. So, if you had a link in one of the iframes - say, in the a iframe, you should be able to do this:

<a href="some.htm" target="back" onclick="location.href='someother.htm';return true;">Some Other Page</a>

Which should change a (the iframe containing the link) to 'someother.htm', and change the 'back' iframe to 'some.htm'.

I'll test this, and if there are any problems, I'll let you know.