Click to See Complete Forum and Search --> : update two frames from on <a href> link
andrew1234
07-19-2003, 12:33 PM
How do i load a two new html pages into two seperate frames
frome one <a href> link?
instead of the normal way where the link targets one frame and loads one new html file into it.
can it be done
thanks
Andrew
David Harrison
07-19-2003, 12:45 PM
I'm about 95% sure that this would work:
In the head of the page with the link in:
<script type="text/javascript"><!--
function twotargets(loc1,loc2){
document.frame1.location.href=loc1;
document.frame2.location.href=loc2;
}
//--></script>
and for the link have:
<a href="abc.html" target="frame1" onclick="twotargets('abc.html','def.html');return false;">Hi</a>
the href and target are there in case javascript is not enabled on the user's PC so that at least one frame gets the correct content loaded into it.
Charles
07-19-2003, 12:48 PM
Originally posted by lavalamp
I'm about 95% sure that this would work: But only for 87% of users. For something that will work and will always work, create a new frameset, just like the old one but with the two different pages. Then simply link to this new frameset.
David Harrison
07-19-2003, 12:55 PM
I did think of that, but then I thought, what if they don't always want to change both pages?
It could be that this is a one off link.
andrew1234
07-20-2003, 05:12 AM
thannks so much for the help
your script did not work..but it gave me an awsome idea
and i could not have done it with out you.
thank you so much
would you like the working script?
David Harrison
07-20-2003, 04:18 PM
Yeah, why not, post away. Although I'm also interested in why the script I posted didn't work. You did remember to change the frame names in it didn't you?
Originally posted by lavalamp
Although I'm also interested in why the script I posted didn't work.It's probably the relationship between the frames. You had:
document.frame1.location.href=loc1;
document.frame2.location.href=loc2;
But maybe it needed:
top.frame1.location.href=loc1;
top.frame2.location.href=loc2;
David Harrison
07-20-2003, 04:47 PM
I thought that document referred to the page as a whole so that the frames were children of the document object.
I don't think so... I don't have time to test right now, but I think top or parent would be what you need.
David Harrison
07-20-2003, 04:57 PM
Fair 'nuff. :)
andrew1234
07-21-2003, 01:30 AM
i had to change it to parent
and i added javascript: to the hyperlink
but i only figured out thati had to change the function to parent. so i'm not sure if i had to change the the hyperlink?
whats the difference between
document. and parent.?
<html>
<head>
<script type="text/javascript">
<!--
function loadframes(loc1,loc2){
parent.frameone.location.href=loc1;
parent.frametwo.location.href=loc2;
}
//--></script>
</head>
<body>
<a href="javascript:loadframes('home.htm','homecontents.htm')">home</a><br>
<a href="javascript:loadframes('about.htm','aboutcontents.htm')">about</a><br>
<a href="javascript:loadframes('help.htm','helpcontents.htm')">help</a><br>
<br>
</body>
</html>
David Harrison
07-21-2003, 01:30 PM
You should really do this:
<a href="#" onclick="loadframes('home.htm','homecontents.htm');return false;">home</a>
to shield your script from any browsers who don't understand javascript, so that they don't go and generate errors.
andrew1234
07-22-2003, 10:48 AM
thanks
look i'm more a designer than a cder
and its amazing how thing work.
and i'm getting into the code thing now because i guess i have to ..
thanks for the advice
andrew