Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Javascript / CSS menu

 
Reply
   X-Cart forums > General > General talk
 
Thread Tools
  #1  
Old 03-28-2006, 01:41 PM
  abeight's Avatar 
abeight abeight is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Cleveland, OH
Posts: 479
 

Default Javascript / CSS menu

Just to forwarn you, this is completely not X-Cart related at all...

I'm trying to find someone that has some javascript experience that can troubleshoot a small problem for me. I have a client site that I used a CSS dropdown menu on. Yesterday I tried adding a javascript stock ticker to the site, and it causes the drop down menu to not work (in IE only). I don't know javascript well enough to figure out what might be causing the compatibility issue.

The site in question is here: www.townsendgroup.com/incognito

Please let me know if you are able to help.

Thank you!!
__________________
~ Andrea Beight
Reply With Quote
  #2  
Old 03-28-2006, 01:42 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Is it a pure CSS menu or does it have a JavaScript component?
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 03-28-2006, 01:55 PM
  abeight's Avatar 
abeight abeight is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Cleveland, OH
Posts: 479
 

Default

The menu has the following script associated with it.

Code:
<script> startList=function(){ if(document.all&&document.getElementById){TopNavRoot=document.getElementById("TopNav"); for(i=0;i<TopNavRoot.childNodes.length;i++){node=TopNavRoot.childNodes[i]; if(node.nodeName=="LI"){node.onmouseover=function(){this.className+=" over";} node.onmouseout=function(){this.className=this.className.replace(" over", "");} }}}} window.onload=startList; </script>
__________________
~ Andrea Beight
Reply With Quote
  #4  
Old 03-28-2006, 01:57 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

This link MIGHT help...

http://www.javascriptkit.com/javatutors/multiplejava.shtml
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #5  
Old 03-28-2006, 02:17 PM
  abeight's Avatar 
abeight abeight is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Cleveland, OH
Posts: 479
 

Default

Thanks for the link. I read the tutorial and grasp the concept. I don't know how to change the code to solve the problem though. Both scripts appear to be using the same code: window.onload
__________________
~ Andrea Beight
Reply With Quote
  #6  
Old 03-28-2006, 02:21 PM
 
zaa zaa is offline
 

X-Cart team
  
Join Date: Apr 2004
Location: Ulyanovsk, Russia
Posts: 125
 

Default

Quote:
Originally Posted by abeight
The menu has the following script associated with it.

Code:
<script> startList=function(){ if(document.all&&document.getElementById){TopNavRoot=document.getElementById("TopNav"); for(i=0;i<TopNavRoot.childNodes.length;i++){node=TopNavRoot.childNodes[i]; if(node.nodeName=="LI"){node.onmouseover=function(){this.className+=" over";} node.onmouseout=function(){this.className=this.className.replace(" over", "");} }}}} window.onload=startList; </script>

Most probably both CSS menu and other JS script try to assign window.onload property, so only one of them (the last one function call) works.
Correct solution is to add the following JS function to your page:

Code:
function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }


and then replace calls like
window.onload=startList;

with

addLoadEvent("startList");
addLoadEvent("name_of_another_onload_function_from _second_script");

That is all.
Reply With Quote
  #7  
Old 03-28-2006, 03:17 PM
  abeight's Avatar 
abeight abeight is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Cleveland, OH
Posts: 479
 

Default

Thanks for the tip. I added this code between the head tags and updated the window.onload properties like you suggested. Now neither script is working. LOL Did I do it wrong?

Code:
<script type="text/javascript"> function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } </script>
__________________
~ Andrea Beight
Reply With Quote
  #8  
Old 03-28-2006, 04:18 PM
 
zaa zaa is offline
 

X-Cart team
  
Join Date: Apr 2004
Location: Ulyanovsk, Russia
Posts: 125
 

Default

Quote:
Originally Posted by abeight
Thanks for the tip. I added this code between the head tags and updated the window.onload properties like you suggested. Now neither script is working. LOL Did I do it wrong?

Code:
<script type="text/javascript"> function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } </script>

Try to remove quotes from names of the functions in calls to addLoadEvent function.

For example, replace

addLoadEvent("startList");

with

addLoadEvent(startList);
Reply With Quote
  #9  
Old 03-28-2006, 05:06 PM
  abeight's Avatar 
abeight abeight is offline
 

X-Adept
  
Join Date: Nov 2003
Location: Cleveland, OH
Posts: 479
 

Default

Zaa, you are my hero! It's working wonderfully now. Thank you so much for your help!!
__________________
~ Andrea Beight
Reply With Quote
Reply
   X-Cart forums > General > General talk


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:42 PM.

   

 
X-Cart forums © 2001-2020