Multiple pages load in multiple iframes from a hyperlink within an iframe

I have recently started learning JavaScript and have had great results.  However, I have a problem with iframes that I can't get around.

I have a main HTML navigation bar on a website's main page.  I am using the following script to load two pages into seperate iframes in addition to a third page loaded with the standard href command:

  <script>
   function pageLoad(pageA,pageB) {
      frames['left'].location.href=pageA
      frames['right'].location.href=pageB

  //where "left" and "right" are names of the iframe set in the iframe tag
   
   }
  </script>

This all takes place in the navigation bar for each hyperlink as follows (note: this navigation bar is not inside an iframe):

  <a href="project_ttl.html" target="top" onclick="pageLoad('projects.html','projects_list.html')">Projects</a>

This is all works great and I successfully load 3 pages with one click.  The problem though is when I want to do the same thing from within an iframe, nothing happens.  For example:  Let's say that I just clicked on the "Projects" hyperlink and all 3 of the new pages load.  Now in "projects.html", which loaded in the iframe named "left", there is another hyperlink that I want to be able to do the same thing with.  For instance lets say that the link in "projects.html" is "ABOUT" and I want it to do the following:

  <a href="bios_ttl.html" target="top" onclick="pageLoad('about.html','bios_list.html')">ABOUT</a>

The href command works fine - that is to say, it changes the "top" iframe from "project_ttl.html" to "bios_ttl.html"- but the javascript function doesn't work to change the other two pages.  I know it probably has something to do with the individual pages not being able to see the iframe names from the main page, but if that is true, then why does the href command still work?

I know I can solve this problem by loading a whole new main page with new "src" files defining the iframes, but I don't want to do that.  There are some other elements (like an animated banner) that I don't want the end users to have to reload everytime they click a link...thus the reason for the iframes.  

There is probably an easy fix that I am overlooking, but this is a very time sensitive question...in other words - urgent.

Thanks for your help.

kearnguyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ZvonkoConnect With a Mentor Systems architectCommented:
All you have to add in the inner pages is the parent reference in the inner pages.
Add also the ",return false" and remove the top target.
Like this:

<a href="#" onclick="parent.pageLoad('about.html','bios_list.html');return false">ABOUT</a>

Changing the top does not make sense, because the does the script have no effect. The top page is loaded and the iframes cannot be changed on the loaded page.
0
 
ZylochConnect With a Mentor Commented:
Hi

First of all, each of your pages have to have a copy of the pageLoad function, because they are different functions, unless your parent top page has a the function. Then, in all your iframe pages, you'd call the function by using parent.pageLoad(params);

Finally, you would want to calibrate your frames to the top. Add this code to your pageLoad function replacing the other two lines:

parent.document.frames['left'].location.href=pageA;
parent.document.frames['right'].location.href=pageB;


Regards,
Zyloch
0
 
ZylochCommented:
Now, if you want this to have a general pageLoad function to call from just your main page, you'd change parent with top

Regards
0
 
ZvonkoSystems architectCommented:
But if you want to load the parent page with a completely new page AND load some iframes on that new loade parent page, then you have to pass the required iframe locations into parent page url as the query string and load a script for analysing the query string. Is that your intention?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.