SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2002
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Conflicting Javascripts

    I know little about Javcascript. I'm using a menu script I copied from http://www.dynamicdrive.com and an image rollover script generated by Adobe Imageready on the same page. The rollover script is called in the HEAD section, along with a few other scripts related to the menu, and the menu script is called in the BODY section.

    My problem is that the menu script works, but the rollover script doesn't. If I remove the call to the menu script from the BODY section, the rollover works, but of course the menu does not.

    Here are the scripts...

    Rollover (note, I have edited out most of the image swap lines to save space):
    HTML Code:
     function newImage(arg) {
       if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
       }
      }
      
      function changeImages() {
       if (document.images && (preloadFlag == true)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
       }
      }
      
      var preloadFlag = false;
      function preloadImages() {
       if (document.images) {
        usa_map_01_usa_map_13_over = newImage("images/usa-map_01-usa-map_13_over.gif");
        usa_map_02_over = newImage("images/usa-map_02-over.gif");
        usa_map_02_usa_map_07_over = newImage("images/usa-map_02-usa-map_07_over.gif");
        usa_map_05_usa_map_14_over = 
      
      // etc, etc, etc...
      
      preloadFlag = true;
       }
      }
    Menu (note, I have edited with carriage returns to *hopefully* make more legible):
    HTML Code:
     var tempEl;
     
     function getRealLeft(imgElem){
      if(ns4){xPos=imgElem.x;}
      else 
       if(!exclude){xPos=eval(imgElem).offsetLeft;tempEl=eval(imgElem).offsetParent;
     	  while(tempEl!=null){xPos+=tempEl.offsetLeft;tempEl=tempEl.offsetParent;}}
       if(mac&&ie5){xPos+=parseInt(document.body.leftMargin);}
       return xPos;
      };
      
     function getRealTop(imgElem){
      if(ns4){yPos=imgElem.y;}
      else
       if(!exclude){yPos=eval(imgElem).offsetTop;tempEl=eval(imgElem).offsetParent;while(tempEl!=null){yPos+=tempEl.offsetTop;tempEl=tempEl.offsetParent;}}
       if(mac&&ie5){yPos+=parseInt(document.body.topMargin);}return yPos;};
     
     /*get offset position based on a function from [url]http://www.webreference.com/js/column33/image.html*/[/url]
       
     var xPos=0;
     var yPos=0;
     var rImg;
     var rPosition=new Array;
     
     if(typeof document.images['anchor'] != "undefined" && 
        typeof document.images['anchor'] != null )
       {rImg=document.images['anchor'];};
     
     var fAry=new Array;
     var fj=0;
     var fImgs=document.images;
     var faryl=0;
     
     if(!exclude){faryl=fImgs.length;}
     
     for(var i=0;i<faryl;i++){
      if(fImgs[i].name=="freeanchor"){fAry[fj]=fImgs[i];fj++;}};
      
     var usingR=0;
     var usingRF=0;
     
     if(!exclude&&rImg){usingR=1;
      if((mac&&ie4)||kde){ie4=0;ie=0;kde=0;exclude=1;}
      else
       if(ns4){xPos=getRealLeft(rImg);yPos=getRealTop(rImg);
        if(menuALIGN!="free"){menuALIGN="left";}absLEFT=xPos;absTOP=yPos;}
        else{xPos=getRealLeft(rImg);yPos=getRealTop(rImg);
     	if(menuALIGN!="free"){menuALIGN="left";}absLEFT=xPos;absTOP=yPos;}}faryl=fAry.length;
        if(faryl>0&&menuALIGN=="free"){usingRF=1;if((mac&&ie4)||kde){ie4=0;ie=0;kde=0;exclude=1;}
       else
        if(ns4){for(i=0;i<faryl;i++){xPos=getRealLeft(fAry[i]);yPos=getRealTop(fAry[i]);
     	if(typeof mI[i]!="undefined"){mI[i][7]=xPos;mI[i][6]=yPos;}absLEFT=0;absTOP=0;}}
        else{for(i=0;i<faryl;i++){xPos=getRealLeft(fAry[i]);yPos=getRealTop(fAry[i]);
     	if(typeof mI[i]!="undefined")
     	 {mI[i][7]=xPos;mI[i][6]=yPos;}absLEFT=0;absTOP=0;}}};
     	
     	var brTok="";
     	
     	if(ie4||(mac&&ie5)){brTok="ie4";}
     	else
     	 if(ie5){brTok="ie5";}
     	 if(ns6||op7||kde){brTok="moz";}
     	 if(op6){brTok="op6";}
     	 if(op5){brTok="op5";}
     	 if(ns4){brTok="ns4";}
     	 if(!exclude){document.write('<script language="javascript1.2" type="text/javascript"
     		 src="'+baseHREF+'menu_'+brTok+'.js"></script>');}
    Like I said, I know little of Javascript, but I see both scripts mention document.images and have a hunch that might be related to my problem. Any help would be greatlyappreciated!

    DAVE

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dave,

    Thanks for posting code, but I don't see the problem there. Is this page online?

    I'm not sure yet if this is relevant, but here are a few tips on solving onload conflicts.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •