PDA

View Full Version : Reloading window content in a Frame triggered by onclick event


roberma
01-04-2003, 05:34 PM
I have the following strange problem with frames and onclick events.

I have defined the following javascript function :


function ReloadMenu(lg) {
if (lg == 'anglais') {location= "English/Menu.html"; alert ("Switching to pages in English");
window.location.reload();
}
else {location = '../Menu.html';
alert ("Switching to pages in French");
window.location.reload();
}
}

The function definition is contained in a file called ReloadMenu.js

In the Menu.html file, which defines a frame in a frameset, I have the following code:

in the head section:

<SCRIPT src="ReloadMenu.js"> </SCRIPT>

In the Body:

<A HREF="English/Accueil.html" TARGET="MainPage" onclick='ReloadMenu("anglais")'>
<IMG SRC="drapeaux_angl_amer.gif" BORDER=0 WIDTH=50 HEIGHT=50 ALT="Go to pages in English"></A>

In the English/Menu.html file:

<A HREF="../Accueil.html" TARGET="MainPage" onClick='ReloadMenu("french")'>
<IMG SRC="../drapeau_fr.gif" BORDER=0 WIDTH=50 HEIGHT=50 ALT="Vers les pages en Français">

It works but only if I put the calls to the alert method in the ReloadMenu function. If I remove these calls, the content of the Menu window in the frame is not reloaded.

Note also that during local tests (on the site on my local computer disk), there is no problem. The call to the alert method is not necessary. I only meet the problem when accessing the site via the Internet.

Who can explain what happens and maybe indicate a way to proceed nicer than the workaround using the call to the alert method.

Thanks

Mr J
01-04-2003, 06:42 PM
Please try the following


function ReloadMenu(lg) {
if (lg == 'anglais') {
parent.menu.location= "English/Menu.html"
}
else {
parent.menu.location = '../Menu.html';
}
}


where menu is the framename that the page is loaded into

roberma
01-05-2003, 03:15 PM
Thanks Mr J.

The code you have sent works at least as well as mine. It is in fact faster.

However, I still have a problem when I connect to the site via the Internet, and I have to modify your suggestion in the following way (otherwise it does not work)

function ReloadMenu(lg) {
if (lg == 'anglais') {parent.menu.location = "English/Menu.html";
"Switching to pages in English";
}
else {parent.menu.location = '../Menu.html';
"Switching to pages in French";
}
}

So note that the call to the alert method is not mandatory, it seems that the function has just to return a value different from the location.
It is OK for me, as I did not like the alert notification but I would like to understand why the function has to behave like this.

Can you explain me (just for my own info ;-)

Anyway thanks and best regards

Mr J
01-05-2003, 05:14 PM
Post your web address so I can have a look, this is a bit puzzling.

I need to see your site and how it is set up.

Something is still wrong somewhere

Thanks

glenngv
01-06-2003, 05:35 AM
try:
<A HREF="English/Accueil.html" TARGET="MainPage" onclick='ReloadMenu("anglais");return false'>