Solved

Targeting multiple Iframes with one link.

Posted on 2004-08-22
11
280 Views
Last Modified: 2012-08-14
Hello,

I am trying to do a basic solution for work in which I have one link that targets two seperate Iframes. Lets say I click on the link "search engines" ... it will display google in Iframe A and yahoo in Iframe B. Heres some code I found on the internet but I dont know much about Javascript, how do I get it working..it keeps giving me an error.  I do not know anything about javascript so I may have even set up the variables or script type wrong.  

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type= javascript>
function doTwo(pageA,pageB)
{
(numberoneIframe.location=pageA);
(numberTwoIframe.location=pageB);
}
</script>
</head>
<body>
<a href="javascript:doTwo('google.com','yahoo.com')">Change Two iframes</a>


<table width="295" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="295" height="105" valign="top"><iframe name="pageA"></iframe><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
<tr>
<td height="105" valign="top"><iframe name="pageB"></iframe><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
</table>
</body>
</html>


Any help would be greatly appreciated!
0
Comment
Question by:Pharcyde616
  • 5
  • 3
  • 3
11 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11864425
function doTwo(A,B)
{
top.frames['pageA'].location.href=A;
top.frames['pageB'].location.href=B;
}

Cd&
0
 

Author Comment

by:Pharcyde616
ID: 11865467
I'm sorry I dont know where to put this in and how to adjust the additional code...as I said..very new to javascript..
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11865794
You just replace this:

function doTwo(pageA,pageB)
{
(numberoneIframe.location=pageA);
(numberTwoIframe.location=pageB);
}

With this:
 function doTwo(A,B)
{
top.frames['pageA'].location.href=A;
top.frames['pageB'].location.href=B;
}

Cd&
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Pharcyde616
ID: 11865827
Doesnt seem to work...says error on page.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11865859
What is the error?

Go to the tools menu >>> internet options... >>> advanced tab, and check the box for
"Display notification for every script error"

Then it will display the text of the error.

Cd&
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
ID: 11866274
There was a basic error in type definition of the script tag.

Here a revised version:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language= javascript>
function doTwo(locA,locB) {
  window.frames.pageA.location=locA;
  window.frames.pageB.location=locB;
}
</script>
</head>
<body>
<a href="javascript:doTwo('http://google.com','http://yahoo.com')">Change Two iframes</a>
<table width="295" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="295" height="105" valign="top"><iframe name="pageA"></iframe><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
<tr>
<td height="105" valign="top"><iframe name="pageB"></iframe><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
</table>
</body>
</html>


0
 

Author Comment

by:Pharcyde616
ID: 11866436
Thanks worked great!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11866458
You are welcome.
0
 

Author Comment

by:Pharcyde616
ID: 11867795
<a href="javascript:doTwo('http://google.com','http://yahoo.com')">Change Two iframes</a>

hey I was wondering why if i put in a location on my hard drive it will not work when it usually does without the multiple point

<a href="javascript:doTwo('c:\' ,'http://yahoo.com')">Change Two iframes</a>
0
 

Author Comment

by:Pharcyde616
ID: 11867950
got that working...but how do you use this code from one

iframe that has the links to the other three iframes.... this works if the link is on the same page as the iframes but what if is from iframe to iframe?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11868384
I did not understood your last question. But definitely you will get problems when READING attributes from a foreign internet domain.
Assigning a location is not reading, it is writing. But after assigning "http://gogle.com" to an iframe you cannot access anyithing from that iframe.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

786 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