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'; 
    } 


  } 



})();
 
typically i find that code that works on FF works on safari, but i may have been lucky.

post some full code and i'll try it, if you like.
 
But i have been told that the buttons do not work in Safari on a MAC.

Show us the buttons - it would be hard to comment without seeing all of your code (HTML, CSS, and other JS).

Perhaps you can post a URL to the page in question?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan, Jpadie

Thanks for the replies, the website that im refering to is;
I will find out the version of Safari and get back to you.

Many thanks
 
Also, you can download and install Safari 3 for Windows. It's free, and seems to do all the things that Safari 3 does on a Mac.

On a side note - IE for the Mac was discontinued several years ago. It is an unsupported product, and not worth spending too much effort fixing (should you ever experience a problem with it). Having said that, I am continually surprised at how well it keeps performing!

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
 
Hi Jeff

Thanks for the response. I have however already tested the site with windows safari and it works fine... thats what was puzzling me.
 
Perhaps you should validate your code before trying to get any JS to work. I'm very sure that this isn't valid in the least:

Code:
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>
<li>

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan

Thanks for pointing that out... the page has now been fully validated but i have had to change to doctype to transitional instead of strict. I've emailed a friend to check the site on his mac but i dont know if it will make a difference?... we shall see.

As for safari errors - if i open the javascript console on my pc version, nothing comes up?

Still waiting to hear what version of safari the person testing it was using.

Tim

 
As for safari errors - if i open the javascript console on my pc version, nothing comes up?

Given it works on the Windows version, that's hardly surprising. You should get your friend to check the Mac Safari console.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
i have no problems with the site on safari for mac (Version 2.0.4 (419.3))
 
I have found out that the version of safari on the mac is 1.3.2 (v312.6)

He also says that when the cursor is over the links, it recognises them and the url appears in the frame of the window but nothing happens when its clicked.

I'm still trying to find out about the Mac console

Tim

 
I would ignore his errors, then. Safari 3 is out. Before that Safari 2. That's 2 major revisions of Safari. Ignore the problem... and suggest he upgrades [smile]

Version 1 was *cough* more than a little buggy.

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
 
I've actually had three people tell me that it doesn't work on their macs now, and they are all having the same problem. I cant find out exactly what version they're all running but its seems to be a significant enough problem.

Does anyone out there have a mac with an newer version of safari that could look at the site?

Perhaps i could just put a font page saying "this site is best viewed with a PC" :)
 
I have no problems with the site running Safari 3.03 on MacOSX 10.4.10 (if that helps any). Nothing in the Javascript console at all. All the buttons work fine.

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
 
I cant find out exactly what version they're all running

Why not ask them, then? All they need to do is click on the "Safari" menu, and then "About Safari".

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I have found that one of them is version 1.3.1 (v312.3.3)... even older than the other friends computer!

I also managed to get them to run the javascript console. There are many lines of;

Undefined value
undefined

With one line near the end of:

TypeError - Null value
undefined

Does this make some sense to anyone?
 
Security Update 2005-007 updates Safari to 2.0 (412.2.2). This tells me your users have not applied any security updates to their OS since July 2005 (more than 2 years).

My only advice to them would be:
Me said:
Use the free Software Update tool to upgrade your OS (including the security updates) which will also update Safari to 2.x and resolve the issues being reported.
Any attempt to continue supporting them is not worth the hassle.

There is another possibility - they are not using Apple hardware. If this is the case, I wish to point out that this is illegal.

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
 
Hi Jeff

Thanks for looking into that. So it is just old versions that are having problems. I know that they're both legal because they're both university lecturers... i guess that they just havn't bothered updating for some reason.

I guess that there is no simple fix that will allow it to work on these earlier versions of safari? Its just that i cant be sure how many people are running the old version and might just give up when they visit the site

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top