SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ive written a DHTML menu using a div tag.
    I write html (a table) to the div tag to represent the menu. It works fine in MSIE.

    It works fine in Netscape too, until you try to press a link that is supposed to open a window in another frame.

    Then netscape calls a function (skrivMeny()), BUT IT IS NOT SUPPOSED TO DO THAT..
    Its not supposed to call any function.

    Take a look boys and girls, and tell me what I have done wrong.

    BTW: It is only the "Kurs->Generelt" link who is supposed to work. Ignore the other links.

    Ive included the table in an "alert window" so you can see what is going on.
    http://www1.moldenett.no/osdata/testmenu/frameset.html


    ------------------


    [This message has been edited by bjarte (edited August 17, 2000).]

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    wayne@sitepoint.com

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <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 = "&lt;table width=\"71%\" cellpadding=\"0\" cellspacing=\"0\" &gt;";
    //looper gjennom hovedgruppene.
    for (i=0; i&lt;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 = "&lt;a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\"&gt;";
    }
    //dersom toppnivået er en link
    else{
    anchorTag = "&lt;a href=\"" + gruppeLink[0]+ "\" target=\"" + gruppeTarget[0] + "\" class=\"hovedgruppe\"&gt;";
    }

    tabell += "&lt;tr&gt; &lt;td colspan=\"2\"&gt;"
    tabell += anchorTag;
    tabell += gruppeNavn[0] + "&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt;";

    //dersom det er denne som er open.
    if (openIndex==i){
    //looper gjennom undergruppene
    for (j=1; j&lt;gruppeNavn.length; j++){
    tabell += "&lt;tr&gt; &lt;td width=\"2%\"&gt;&nbsp;&lt;/td&gt; &lt;td width=\"98%\"&gt;" + "&lt;a href=\"" + gruppeLink[j] + "\" class=\"undergruppe\" target=\"" + gruppeTarget[j] + "\"&gt;" + gruppeNavn[j] + "&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt;";
    }
    }
    }

    tabell += "&lt;/table&gt;";
    alert(tabell);
    //***************************BROWSER DEPENDENT CODE*************************************

    //Dersom MSIE
    if (document.all){
    layer=meny1;
    layer.innerHTML = tabell;
    layer.style.display="block";
    }
    //Dersom Netscape
    else if (document.layers){
    layer=document.layers["meny1"];
    layer.document.open();
    layer.document.writeln(tabell);
    layer.document.close();
    layer.visibility = "show";

    }
    //Dersom noe annet
    else{
    alert("Denne siden krever MSIE eller Netscape browser av nyere type");
    }

    //***************************BROWSER DEPENDENT CODE*******************************

    }

  4. #4
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Actually it doesn't...

    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 = "&lt;table width=\"71%\" cellpadding=\"0\" cellspacing=\"0\" &gt;";
    //looper gjennom hovedgruppene.
    for (i=0; i&lt;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 = "&lt;a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\"&gt;";
    }
    //dersom toppnivået er en link
    else{
    anchorTag = "&lt;a href=\"" + gruppeLink[0]+ "\" target=\"" + gruppeTarget[0] + "\" class=\"hovedgruppe\"&gt;";
    }

    tabell += "&lt;tr&gt; &lt;td colspan=\"2\"&gt;"
    tabell += anchorTag;
    tabell += gruppeNavn[0] + "&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt;";

    //dersom det er denne som er open.
    if (openIndex==i){
    //looper gjennom undergruppene
    for (j=1; j&lt;gruppeNavn.length; j++){
    tabell += "&lt;tr&gt; &lt;td width=\"2%\"&gt; &lt;/td&gt; &lt;td width=\"98%\"&gt;" + "&lt;a href=\""
    + gruppeLink[j] + "\" class=\"undergruppe\" target=\""
    + gruppeTarget[j] + "\"&gt;" + gruppeNavn[j] + "&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt;";
    }
    }
    }

    tabell += "&lt;/table&gt;";
    [/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 = "&lt;a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\"&gt;";
    [/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 = "&lt;a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" onClick=\"skrivMeny(" + skalOpnes + "); return false\;\"&gt;";}
    else if NS {
    anchorTag = "&lt;a href=\"" + gruppeLink[0]+ "\" class=\"hovedgruppe\" return false\;\"&gt;"; }
    [/code]

    Only then will Netscape not call the function.

    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    wayne@sitepoint.com


    [This message has been edited by wluke (edited August 17, 2000).]

    [This message has been edited by wluke (edited August 17, 2000).]

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My english isnt very good. Sorry.

    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:
    &lt;a href="somelink_link" class="undergruppe" target="main"&gt;,
    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-&gt;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...

    BTW: Im using Netscape 4.7

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dose anybody know why?

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out. If I replace
    &lt;a href="whateverlink" target="main"&gt;
    with
    &lt;a href="#" onClick="window.open('whateverlink', 'main'); return false;"&gt;
    then Netscape doesnt go off eating cake.
    Now I have a SUPERMENU!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •