Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript not working in Safari

Status
Not open for further replies.

ringod

Technical User
Aug 3, 2007
12
GB
Hi

Im using Javascript to expand a unordered list menu and it works on my pc in the latest versions of Opera, Safari, Firefox and IE. But i have been told that the buttons do not work in Safari on a MAC. It does however work in IE on a MAC.

Is there a difference between the way Safari on a MAC would read the code?

Many thanks


Code:
var dMenu = (function(){ 


  var menu; 


  function parentLi(el) { 
    do { 
      if (el.tagName.toLowerCase() == 'li') return el 
    } while (el = el.parentNode) 
  } 


  function openParentUls(el) { 
    while (el != menu) { 
      if (el.tagName.toLowerCase() == 'ul') el.style.display = ''; 
      el = el.parentNode; 
    } 
  } 


  function closeAll(el) { 
      var el = el || menu; 
      var uls = el.getElementsByTagName('ul'); 
      var i = uls.length; 
      while(i--){uls[i].style.display = 'none';} 
    } 


  return { 
    init: function (id) { 
      if (!document.getElementsByTagName || 
          !document.getElementById ) { 
        return; 
      } 


      menu = document.getElementById(id); 


      if (menu) { 
        this.closeAll(menu); 
        var uls = menu.getElementsByTagName('ul'); 
        var i = uls.length; 
        while (i--) { 
          parentLi(uls[i]).onclick = this.doClick; 
        } 
      } 
    }, 


    closeAll: function (el) { 
      closeAll(el); 
    }, 


    doClick: function(e) { 
      var e = e || window.event; 
      var tgt = e.target || e.srcElement; 

      if(tgt.tagName.toLowerCase()!='a') return;

      e.cancelBubble = true; 
      if (e.stopPropagation) e.stopPropagation(); 


      while (tgt != this) { 
        if (tgt.tagName.toLowerCase() == 'ul') return; 
        tgt = tgt.parentNode; 
      } 


      var firstUl = this.getElementsByTagName('ul')[0]; 
      var firstUlDisplay = firstUl.style.display; 
      closeAll(menu); 
      openParentUls(this); 
      firstUl.style.display = ('none' == firstUlDisplay)? '' : 'none'; 
    } 


  } 



})();
 
There is no simple fix for those old browsers. Very very very few people will be running this old browser version on a regular basis - Apple have a regular (free) software update program and most people would have been updating regularly (and so they will be using modern versions of Safari).

I wouldn't worry about losing people with such a specific browser - not until you can measure that number and come to the conclusion that it is a problem.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top