Solved

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

Posted on 2004-09-07
4
1,365 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
  • 2
  • 2
4 Comments
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now