/    Sign up×
Community /Pin to ProfileBookmark

Menus that work in Netscape and MSIE

Hi

Appologies for asking a question that probably gets asked all the time, but I was hoping to use dhtml to control the visibility of an element (a menu of links) using style.

I can make it work with MSIE but in Netscape nothing happens.

This is the js function that controls it. Is there something wrong with the script or is there another issue elsewhere that I’m doing wrong…

[code]
function barTog(menu) {

if (document.layers) {
menu1 = document.layers[menu];
} else if (document.all) {
menu1 = document.all(menu).style
}

if (menu1.visibility == visible) {
menu1.visibility = hidden;
}
else {
menu1.visibility = visible;
document.loginform.username.focus();
}
if (lastMenu != menu) {
closeMenus(lastMenu);
}
lastMenu = menu;

}
[/code]

Help advice, pointers, or alternatives appreciated.

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayMar 31.2004 — Try using:

document.getElementById(menu).style.visibility = "visible";
Copy linkTweet thisAlerts:
@KorApr 03.2004 — 
  • - NS4 uses different values for visibility attribute (show/hide)

  • - IE 4 uses document.all as reference

  • - new browsers IE5+, NS6+, Mozilla, Opera use document.getElementById as reference

  • - IE4 , IE5+, NS6+, Mozilla use [i]object[/i].style.visibility


  • Try this cross-browser solution:

    [code=php]
    function barTog(menu) {
    if(document.getElementById){
    menu1 = document.getElementById(menu).style.visibility;
    if(menu1=='visible'){menu1='hidden'}
    else{menu1='visible'}
    }
    }
    else if(document.all){
    menu1 = document.all[menu].style.visibility;
    if(menu1=='visible'){menu1='hidden'}
    else{menu1='visible'}
    }
    }
    else if(document.layers){
    menu1 = document.layers[menu].visibility;
    if(menu1=='show'){menu1='hide'}
    else{menu1='show'}
    }
    }
    [/code]


    don't forget to

  • - give id="" instead of name="" to the objects

  • - give a CSS absolute position to the objects (<tag style="position:absolute".....) otherwise NS4 woun't fire the function
  • Copy linkTweet thisAlerts:
    @zingmatterauthorApr 03.2004 — That's great. Thanks. I'll get working on it now.

    ?
    ×

    Success!

    Help @zingmatter spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...