View Full Version : loading into two frames with one link
deceeced
12-12-2002, 03:14 PM
Hello,
I do admit that I am new to Javascript. I know the basics and am slowly improving. I have run into a problem that I can't figure out. I am creating a site in framesets. The site has three frames. The top is for navigation and the bottom two for everything else. I was wondering now, that if a user clicked on the menu in the top navigation menu, would it be possible to have two pages load into the other two frames below? I have tried making simple functions using window.open and calling them with onLoad in one frame page to have it open a new page in the other frame. But, I can't seem to get the page to open in the other frame. I can't target the other frame, is it possible to target the other frame? Or is there an easier way to do this? Have two separate pages load into two separate frames by clicking on one link?
Deceeced
joh6nn
12-12-2002, 03:32 PM
I can't target the other frame, is it possible to target the other frame?
... ?
here's a tutorial for you, at webmonkey:
http://hotwired.lycos.com/webmonkey/97/02/index4a.html
Hey -
If I'm understanding you correctly you want to have 2 different pages load in 2 different frames with the click of one link..
Here's a function you could call from a
<script>
function setFrames() {
document.frames('frameName1').src=="/link/to/page.html";
document.frames('frameName2').src=="/link/to/page2.html";
}
</script>
...
<a href="javascript:void(0)" onclick="setFrames()">click</a>
This may be Microsoft Specific but I'm not entirely sure.
Hope this helps
deceeced
12-12-2002, 05:08 PM
thanks joh6nn, and lupo, for the replies.
i took a look at the webmonkey source. it was very helpful. however, i am using three frames. the links are all in the top frame. i need the two bottom frames to load new pages. can i alter this script to be used in this way?
i tried the code you gave lupo. but it produces an error. IE gives the error: Exception Occured at line 30. on line 30 of the page is this:
document.frames('PopUp').src=="products/fresheners/screen1.htm";
any suggestions for the cause of this problem?
thanks a lot for your help
document.frames('PopUp').src=="products/fresheners/screen1.htm";
This line is an equivalency test and not a value assignment ... take out one of the "=" yielding:
document.frames('PopUp').src="products/fresheners/screen1.htm";
Also, I'm assuming that PopUp is a frame and not a spawned window?
glenngv
12-13-2002, 10:29 AM
use window.open and specify the target:
function setFrames() {
window.open("url1","targetFrameNameHere1")
window.open("url2","targetFrameNameHere2")
}
ChiZel_MunKee
12-13-2002, 02:43 PM
Here's one I know that works, because I'm using it now. Hope it helps.
function change2()
{
top.FRAMENAME.document.location="whatever.htm"
top.FRAMENAME.document.location="however.htm"
}
For the links onclick event, just call this function.
Camel_Booter
04-15-2003, 06:30 AM
Well hay i cant get none of these to work ould someone type a whole working script...sorry i'm a n00b Thanks for helping!!:)
Garadon
04-15-2003, 08:18 AM
remember to change the stuff written with capital letters below :)
function change2(url1,url2)
{
window.open(url1,"FRAMENENAME1");//change FRAMENENAME1 to the name of ur frame u want url1 to be loaded into
window.open(url2,"FRAMENENAME2");//change FRAMENENAME2 to the name of ur frame u want url2 to be loaded into
}
in the link tags put this code:
onClick="change2('FILE1','FILE2');" //change FILE1 and FILE2 to the file names u want loaded
sage45
04-17-2003, 04:22 PM
One of my personal favorites:
<SCRIPT LANGUAGE="JavaScript">
function setFrame(frameName, frameSrc) {
parent[frameName].location=(frameSrc + '.htm');
}
</SCRIPT>
Link to be written as such:
<A HREF="javascript:setFrame('frameName1','frameContent1');setFrame('frameName2','frameContent2')">link</A>
Where frameName[x] = the Frame you will be populating or writting to.
-and-
Where frameContent[x] = the webpage you will be openning into the frame.
Ofcourse you can do things like modifying the script to meet any page specific needs:
<SCRIPT LANGUAGE="JavaScript">
function setFrameHTML(frameName, frameSrc) {
parent[frameName].location=(frameSrc + '.html');
}
function setFrameASP(frameName, frameSrc) {
parent[frameName].location=(frameSrc + '.asp');
}
function setFramePHP(frameName, frameSrc) {
parent[frameName].location=(frameSrc + '.php');
}
// --- This last one is untested but should work as well
function setFrameNT(frameName, frameSrc) {
parent[frameName].location=(frameSrc);
}
// --- For the last one you would include the extension onto
// --- your frameSrc in the Link.
// --- Example:
// --- <A HREF="javascript:setFrameNT
// --- ('frameName1','frameContent1.htm');
// --- setFrameNT('frameName2','frameContent2.asp')">
// --- link</A>
</SCRIPT>
HTH,
-sage-
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.