Forum Moderators: open

Message Too Old, No Replies

Changing two frames with Javascript

need help!

         

margaro

10:07 am on Dec 1, 2006 (gmt 0)

10+ Year Member



My website has 3 frames: the top one, the left one and the right one. The left one is divided into two frames: the top contains three flags (German,English and Spanish) and the bottom one the menu with the buttons: CV, Documents, contact,etc...

When you click on the first flag (German), two frames are supposed to change:
1-the menu in the left-bottom frame. (should change into my german version of the menu: "navi_ger.html")
2-the document that is loaded on the right frame, for example: "cv/MG_CV.html" should change to the corresponding German version of my CV, i.e.:"cv/MG_Lebenslauf.html".

Another example: supposing that the page: my documents ("documents.html") is loaded on the right frame, you click on the German flag and the menu and the "my documents" page change into German menu ("navi_ger.html") and "documents_ger.html"

but my javascript program doesn't do the trick! I don't know what is wrong... Can somebody help?

<html><head><title>language</title>
<script language="JavaScript">
<!--
function change_frames(file1,file2){
parent.frames[2].location.href=file1
parent.frames[3].location.href=file2
}
var mainframe;
mainframe=top.location.href;
function toGerman(){

if (mainframe=="cv/MG_CV.html"¦¦"cv/MG_Lebenslauf.html"¦¦"cv/MG_Hojadevida.html")
{
javascript:change_frames('navi_ger.html','cv/MG_Lebenslauf.html')
};
if (mainframe=="documents.html"¦¦"documents_esp.html"¦¦"documents_ger.html")
{
javascript:change_frames('navi_ger.html','documents_ger.html')

};
if (mainframe=="hobbies.html"¦¦"hobbies_ger.html"¦¦"hobbies_esp.html")
{
javascript:change_frames('navi_ger.html','hobbies_ger.html')
};

if (mainframe=="contact.html"¦¦"kontakt.html"¦¦"Contacto.html")
{
javascript:change_frames('navi_ger.html','kontakt.html')
}
else{
javascript:change_frames('navi_ger.html','home_ger.html')

};

}

//-->
</script>
</head>
<body style="color: rgb(0, 0, 0); background-image: url(203b.jpg);" alink="#000099" link="#000099" vlink="#990099">

<table border="0" cellpadding="0" cellspacing="0" width="180">
<tbody>
<tr> <td><div align="center">

<form>
<input type="image" alt="Deutsche Version" src="index_dateien/deu.gif" border="0" onclick="javascript:toGerman()">

<br><br>
<input type="image" alt="English Version" src="index_dateien/eng.gif" border="0" onclick="javascript:change_frames('navi.html','home.html')"><br><br>
<input type="image" alt="Version Espanola" src="index_dateien/esp.gif" border="0" onclick="javascript:change_frames('navi_esp.html','home_esp.html')">
</form>
</div></td></tr></tbody>
</table>

</body>
</html>

daveVk

11:34 pm on Dec 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I understand corrcect you have this structure
- main window
--- top frame
--- left frame
----- flags frame
----- menu frame
--- right frame

function change_frames refers to "parent" the meaning of which will depend on context of call, eg left is parent of flags. Change change_frames to directly refer to required frames

margaro

2:55 pm on Dec 4, 2006 (gmt 0)

10+ Year Member



this is my structure:
<frameset rows="15%,85%">
<frame src="head.html"name="head">
<frameset cols="18%,82%">
<frameset rows="40%,60%">
<frame src="language.html" name="language">
<frame src="navi.html" name="navi">
</frameset>
<frame src="home.html" name="main">

but I can't figure out how to tell Javascript to look into frame "main" and according to what it finds loaded there, do something!

i.e. if Javascript finds my CV in English in the frame "main", when you click on the German flag, javascript should change the frame "main" into my CV in German.

daveVk

1:32 am on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First ensure each <frameset> has matching </frameset>. I have not used framesets, I think code below is trying to refer to 3rd and 4th frame of a particular frameset ( frameset that contains current frame ie "parent" )

function change_frames(file1,file2){
parent.frames[2].location.href=file1
parent.frames[3].location.href=file2
}

kaled

3:38 am on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't looked for a fault but I will say that the concept is wrong.

You should use the <body onload> event in the first page to load the second page into its frame (using location.replace()).

This method means that
a) standard links can be used (no javascript, just a target).
b) the Back button will work correctly.
c) the frames should always be synchronised.

You may need to perform a test before reloading the second page unnecessarily.

Kaled.