Browser specific JavaScript error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SwapnilD
    New Member
    • Jan 2010
    • 41

    Browser specific JavaScript error

    I'm having a problem with submenu list. In my website I have code which populate a list of submenus onmouseover it works fine for IE but doesn't work for Mozilla and Chrome. Below is the code that.

    Code:
    <style>
    .menu { 
    color: #000000; font-family: arial; font-size: 11px; line-height: 12px;
     padding-top: 3px;
    position: absolute; visibility: hidden; width: 175px; zindex: 99; 
    }
    .unnamed1 {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small}
    .txtheader1 {
    font-family: Verdana; font-size: 11px}
    </style>
    <script language="Javascript" src="fnc_menu.js"></script>
    <script language=javascript>
    <!--
    version = '0';
    var isMacIE = ( (navigator.userAgent.indexOf("IE 4") > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );
    browserName = navigator.appName;           
    browserVer = parseInt(navigator.appVersion); 
    if (browserName == "Netscape" && browserVer >= 4)version = "n4";
    else if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) version = "e4";
                 
        if (version == "n4" || version == "e4" && !isMacIE)     
    	{         
    		document.write('' +
    		'<div id=menu1 class="menu"><table  border=0 cellspacing=0 cellpadding=0>'+
    		'<tr>'+
    	    '<td ><a href="company.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mp&quot;,&quot;&quot;,&quot;http://bytes.com/images/over_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/over_btn.jpg" name="mp" border="0"></a></td>'+
    	    '<tr>'+
            '<td ><a href="location.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mpp&quot;,&quot;&quot;,&quot;http://bytes.com/images/loc_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/loc_t_btn.jpg" name="mpp" border="0"></a></td>'+
    		'<tr>'+
            '<td ><a href="team.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mpl&quot;,&quot;&quot;,&quot;http://bytes.com/images/team_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/team_t_btn.jpg" name="mpl" border="0"></a></td>'+
            '</tr>'+
            '</table>'+
    		'</div>' +
    
    		'<div id=menu2 class="menu"><table  border=0 cellspacing=0 cellpadding=0>'+
    		'<tr>'+
    		'<td><a href="software.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mpll&quot;,&quot;&quot;,&quot;http://bytes.com/images/soft_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/soft_t_btn.jpg" name="mpll" border="0"></a></td>'+
    		'<tr>'+
            '<td ><a href="tech_consult.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mplll&quot;,&quot;&quot;,&quot;http://bytes.com/images/tech_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/tech_t_btn.jpg" name="mplll" border="0"></a></td>'+
    		'<tr>'+
            '<td ><a href="design.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mpllll&quot;,&quot;&quot;,&quot;http://bytes.com/images/des_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/des_t_btn.jpg" name="mpllll" border="0"></a></td>'+	             
    		'</tr>'+
    		'<td ><a href="fractit.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mpllll2&quot;,&quot;&quot;,&quot;http://bytes.com/images/fractit_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/fractit_t_btn.jpg" name="mpllll2" border="0"></a></td>'+	             
    		'</tr>'+
    		'</table>'+
    		'</div>' +
    
    		'<div id=menu3 class="menu"><table  border=0 cellspacing=0 cellpadding=0>'+
    		'<tr>'+
    		'<td  ></td>'+
    		'<td ></td>'+
    		' </tr>'+
    		'</table>'+
    		'</div>' +
    		'<div id=menu4 class="menu"><table  border=0 cellspacing=0 cellpadding=0>'+
            '<tr>'+
    		'<td><a href="information.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mplllll&quot;,&quot;&quot;,&quot;http://bytes.com/images/info_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/info_t_btn.jpg" name="mplllll" border="0"></a></td>'+
    		'<tr>'+
            '<td><a href="quote.asp" onmouseover="timer(1);MM_swapImgRestore();MM_swapImage(&quot;mpllllll&quot;,&quot;&quot;,&quot;http://bytes.com/images/get_t_btn_ov.jpg&quot;,1);" onmouseout="timer(0);MM_swapImgRestore();" class=sub><img src="http://bytes.com/images/get_t_btn.jpg" name="mpllllll" border="0"></a></td>'+
    		'</tr>'+
    		'</table>'+
    		'</div>' +
    
    		'<div id=menu5 class="menu"><table  border=0 cellspacing=0 cellpadding=0>'+
    		'<tr>'+
    		'<td  ><a href="job_oppur.htm" onmouseover=timer(1); onmouseout=timer(0); class=sub><img src="http://bytes.com/images/oppur.jpg"  border="0"></a></td>'+
    	
    			                            
    		' </tr>'+
    		'</table>'+
    		'</div>')
    	}
    
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    
    function MM_findObj(n, d) { //v3.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
      return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    Please Help
    Last edited by Dormilich; Mar 26 '10, 11:06 AM. Reason: Please use [code] tags when posting code
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Look at your code:
    Code:
    var isMacIE = ( (navigator.userAgent.indexOf("IE 4") > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );
    browserName = navigator.appName;           
    browserVer = parseInt(navigator.appVersion); 
    if (browserName == "Netscape" && browserVer >= 4)version = "n4";
    else if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) version = "e4";
     
        if (version == "n4" || version == "e4" && !isMacIE)     
        {
    It's old and ancient. It's checking for IE4+ and Netscape 4+ and ignoring everyone else! Get rid of the browser sniffing and there's a chance it may work in other browsers.

    Comment

    Working...