CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985

    Dir Tree works in IE but not NS

    The following JavaScript works in IE but not Netscape. Is there an easy way to get it to work in both without detecting the browser? What about another scripting language?

    What it does is submits to a CGI that displays a directory Structure.

    Code:
    <script language="JavaScript">
    <!--
        var openDirNum=4;
        var openDirs = new Array(4);
    
    openDirs[0]="uploads";
    openDirs[1]="uploads/test1";
    openDirs[2]="uploads/test1/test1_1";
    openDirs[3]="uploads/test1/test1_1/test1_1_1";
    
    function dirOnClick(dirName)   {
        var i;
        var bWasOpen = false;
        var oDirSel;
        var iIndex = 0;
    
        for (i=0; i < openDirNum; i++)    {
            if (openDirs[i] == dirName)    {
                for (var j=i+1; j < openDirNum; j++)    {
                    if (openDirs[j].indexOf(openDirs[i])==0)
                        openDirs[j] = "";
                    else
                        j = openDirNum + 1;
                }
                openDirs[i] = "";
                bWasOpen = true;
                i = openDirNum + 1;
            }
        }
    
        oDirSel = document.createElement("INPUT");
        oDirSel.type = "HIDDEN";
        oDirSel.name ="DirSelected";
    
        if (bWasOpen == false)  {
            oDirSel.value=dirName;
            document.frmDirs.appendChild(oDirSel);
            submitOpenDirs(dirName);
        } else  {
            iIndex = dirName.lastIndexOf('/')
            if (iIndex > 0)
                oDirSel.value=dirName.substring(0, iIndex);
            else
                oDirSel.value="";
            document.frmDirs.appendChild(oDirSel);
            submitOpenDirs();
        }
    
    }
    function submitOpenDirs()   {
        var i = 0;
        var iOpen = 0;
        var oFileDirs;
        for (i=0; i < openDirNum; i++)    {
            if (openDirs[i] != "")  {
                iOpen++;
                oFileDirs = document.createElement("INPUT");
                oFileDirs.type = "HIDDEN";
                oFileDirs.name ="OpenDir"+iOpen;
                oFileDirs.value=openDirs[i];
                document.frmDirs.appendChild(oFileDirs);
            }
        }
        if (submitOpenDirs.arguments.length > 0)    {
            iOpen++;
            oFileDirs = document.createElement("INPUT");
            oFileDirs.type = "HIDDEN";
            oFileDirs.name ="OpenDir"+iOpen;
            oFileDirs.value=submitOpenDirs.arguments[0];
            document.frmDirs.appendChild(oFileDirs);
        }
    
        frmDirs.submit();
    }
    
    //-->
    </script>

  2. #2
    Join Date
    Aug 2002
    Location
    Reykjavik, Iceland
    Posts
    201
    Which version of Netscape are you referring to?

    It will never work with Netscape 4.x because it uses W3C DOM JavaScript methods such as appendChild() for dynamically changing a node tree on the fly.

    The W3C DOM is supported by Netscape 6.1+ however. Have you tested it in this?

  3. #3
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    4.7 for Linux. It doesn't work with Konqueror either.

  4. #4
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    Ok it somewhat works in Konqueror.

    I changed the Type to text and "Alert"ed the name, the name is correct and it is displaying the correct value once I append the Input Type Text, but it isn't being submitted.

    Oh and I remarked out the the code to automatically submit and added a submit button, so I could see what was going on.

    I also tried using .setAttribute with the same results.
    Last edited by Goodz13; January 29th, 2003 at 09:28 PM.

  5. #5
    Join Date
    Aug 2002
    Location
    Reykjavik, Iceland
    Posts
    201
    It should work in Mozilla, since it supports the W3C DOM

  6. #6
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    Sorry I just realized that I never thanked you. Thank you very much.
    I tested it on different browsers and here's my results. I guess I could have done a search to see which browsers supported W3C DOM, but I tend to do things the hard way

    Internet Explorer 5.0 - Works!
    Mozilla 1.0.1 - Doesn't Work!
    Mozilla 1.0.2 - Works!
    Netscape 4.x - Doesn't Work
    Netscape 7.0.1 - Works!
    Konqueror 3.0.3-14 - Somewhat works - Doesn't submit properly

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured