Solved

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

Posted on 2004-09-07
4
1,384 Views
Last Modified: 2010-05-18
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.

0
Comment
Question by:kearnguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 100 total points
ID: 12001126
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 12001128
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 400 total points
ID: 12001425
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 12001440
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

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question