Your function that writes the table out originally does not take into account whether the user is using Netscape or IE. Your telling all browsers - Onlick="skrivMeny(index)". You need to make your at least index -1 write a proper table for Netscape or change your Onload statement so that it calls one table generator for Netscape and another for IE. The second option is probably the easier of the two.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote/font><HR>Originally posted by wluke: Your function that writes the table out originally does not take into account whether the user is using Netscape or IE. Your telling all browsers - Onlick="skrivMeny(index)". <HR></BLOCKQUOTE>
The function TAKES browsers into account.
First the function writes out the table, then it decides which browser, then it writes out the table accordinly.
This is the function:
function skrivMeny(openIndex){
tabell = "<table width=\"71%\" cellpadding=\"0\" cellspacing=\"0\" >";
//looper gjennom hovedgruppene.
for (i=0; i<linkNavn.length; i++){
gruppeNavn = linkNavn[i].split(",");
gruppeLink = linker[i].split(",");
gruppeTarget = target[i].split(",");
//finner ut om submenyen skal åpnes neste gang.
skalOpnes=i;
if (openIndex==skalOpnes){
skalOpnes=-1;
}
var anchorTag;
//dersom topnivået skal ekspandre resten av menyen.
if (gruppeLink[0] == "#"){
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\">";
}
//dersom toppnivået er en link
else{
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" target=\"" + gruppeTarget[0] + "\" class=\"hovedgruppe\">";
}
If Netscape isn't supposed to call any functions from the links then you have to build a different table structure for it.
The entire code for building the table does not take different browsers into account. Only the code for writing it to the page does.
The code you need to make cross-browser is:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
function skrivMeny(openIndex){
tabell = "<table width=\"71%\" cellpadding=\"0\" cellspacing=\"0\" >";
//looper gjennom hovedgruppene.
for (i=0; i<linkNavn.length; i++){
gruppeNavn = linkNavn[i].split(",");
gruppeLink = linker[i].split(",");
gruppeTarget = target[i].split(",");
//finner ut om submenyen skal åpnes neste gang.
skalOpnes=i;
if (openIndex==skalOpnes){
skalOpnes=-1;
}
var anchorTag;
//dersom topnivået skal ekspandre resten av menyen.
if (gruppeLink[0] == "#"){
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\">";
}
//dersom toppnivået er en link
else{
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" target=\"" + gruppeTarget[0] + "\" class=\"hovedgruppe\">";
}
//dersom det er denne som er open.
if (openIndex==i){
//looper gjennom undergruppene
for (j=1; j<gruppeNavn.length; j++){
tabell += "<tr> <td width=\"2%\"> </td> <td width=\"98%\">" + "<a href=\""
+ gruppeLink[j] + "\" class=\"undergruppe\" target=\""
+ gruppeTarget[j] + "\">" + gruppeNavn[j] + "</a> </td> </tr>";
}
}
}
tabell += "</table>";
[/code]
As the code clearly states, everytime it builds a link it adds an onClick event handler to call skrivMeny() regardless of what browser your using.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\">";
[/code]
If Netscape is not supposed to call this function at all your code should be something like this pseudocode.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
if IE {
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\">";}
else if NS {
anchorTag = "<a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" return false\;\">"; }
[/code]
Im supposed to get the same table for Netscape and MSIE.
The skrivMeny() fuction is supposed to be called in the top level links.
The problem is that when you press a sublevel link looking like this:
<a href="somelink_link" class="undergruppe" target="main">,
then (using Netscape) the function skrivMeny() is called. However, there is no refrence to the skrivMeny() function in the anchor tag. So my question is: Why does netscape call this function, and how can I prevent it.
The link that is supposted to open main2.html in the main frame is the Kurs->Generelt link. This works in MSIE. The same anchor tag in Netscape fails.
BTW: Thank you alot (wluke) for helping me developing my soon-to-be supermenu...
I figured it out. If I replace
<a href="whateverlink" target="main">
with
<a href="#" onClick="window.open('whateverlink', 'main'); return false;">
then Netscape doesnt go off eating cake.
Now I have a SUPERMENU!!!
Bookmarks