Results 1 to 2 of 2

Thread: Targeting two IFrames with one link

  1. #1
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Targeting two IFrames with one link

    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"
    Code:
    function changeLink(link1,link2) {
    eval("parent.a.location='"+link1+"'");
    eval("parent.back.location='"+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!
    Last edited by 13-days; 05-26-2008 at 03:25 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    HTML Code:
    <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:

    HTML Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    meenakshi (05-28-2008)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •