browser issue causing problem in dropdown feature

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Whitney

    browser issue causing problem in dropdown feature

    On the left side of the main webpage I have some menu options that
    have a drop-down feature that is controlled with javascript. You click
    on the main heading and the links for that section show up. Click on
    it again and they disappear. This works great in IE6 but doesn't seem
    to work in Netscape 7.

    I have included the main javascript code below, along with a sample of
    the Menu code. What (if anything) do I need to tweak to get this to
    work under Netscape?


    javascript code:
    <script language=JScrip t>
    document.onclic k = DropDownMenu;

    function DropDownMenu() {
    var LinkClicked, DivName, TargetDiv;

    LinkClicked = window.event.sr cElement;
    if (LinkClicked.cl assName == "Category") {
    DivName = "Div_" + LinkClicked.id. substr(5,
    LinkClicked.id. length);
    TargetDiv = document.all(Di vName);
    if (TargetDiv.styl e.display == "")
    TargetDiv.style .display = "none";
    else
    TargetDiv.style .display = "";
    } // if
    } // DropDownMenu
    </script>

    Sample of Menu item:
    <ul>
    <li><b><a id=Link_Memoria m class=Category href=#>In
    Memoriam</a></b></li>
    <div id=Div_Memoriam style="display: none">
    <ul>
    <li><a href="memoriam/DickPollitz.htm ">Dick Pollitz</a></li>
    </ul>
    </div>
    </ul>
  • Grant Wagner

    #2
    Re: browser issue causing problem in dropdown feature

    Whitney wrote:
    [color=blue]
    > On the left side of the main webpage I have some menu options that
    > have a drop-down feature that is controlled with javascript. You click
    > on the main heading and the links for that section show up. Click on
    > it again and they disappear. This works great in IE6 but doesn't seem
    > to work in Netscape 7.
    >
    > I have included the main javascript code below, along with a sample of
    > the Menu code. What (if anything) do I need to tweak to get this to
    > work under Netscape?
    >
    >
    > javascript code:
    > <script language=JScrip t>[/color]

    Netscape 7 doesn't support any language called "JScript". Use:

    <script type="text/javascript">
    [color=blue]
    > document.onclic k = DropDownMenu;
    >
    > function DropDownMenu() {
    > var LinkClicked, DivName, TargetDiv;
    >
    > LinkClicked = window.event.sr cElement;[/color]

    Netscape 7 doesn't have an Event object attached to the default window
    object. The event is passed as the first parameter to the function. Nor
    does Netscape 7 have a "srcElement " property of the event, it has a
    "target" property:

    function DropDownMenu(e) {
    var LinkClicked, DivName, TargetDiv;

    LinkClicked = e ? e.target : window.event.sr cElement;
    [color=blue]
    > if (LinkClicked.cl assName == "Category") {
    > DivName = "Div_" + LinkClicked.id. substr(5,
    > LinkClicked.id. length);
    > TargetDiv = document.all(Di vName);[/color]

    Netscape 7 doesn't support document.all:

    if (document.getEl ementById) { // NS6+, IE5.5+,Opera 7+
    TargetDiv = document.getEle mentById(DivNam e);
    } else if (document.all) { // IE4
    TargetDiv = document.all(Di vName);
    }
    [color=blue]
    > if (TargetDiv.styl e.display == "")
    > TargetDiv.style .display = "none";
    > else
    > TargetDiv.style .display = "";
    > } // if
    > } // DropDownMenu
    > </script>
    >
    > Sample of Menu item:
    > <ul>
    > <li><b><a id=Link_Memoria m class=Category href=#>In
    > Memoriam</a></b></li>
    > <div id=Div_Memoriam style="display: none">
    > <ul>
    > <li><a href="memoriam/DickPollitz.htm ">Dick Pollitz</a></li>
    > </ul>
    > </div>
    > </ul>[/color]

    With the changes indicated, I tested it in IE6SP1, Mozilla 1.5a and Opera
    7.11 and it worked.

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Gain technical skills through documentation and training, earn certifications and connect with the community


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    Working...