alabina
asked on
Multiple javascripts interfering with each other
My site is a css site and I am using 2 javascripts, (matching column heights from killersites.com and a slideshow from codelifter). Both scripts are in a separate .js file and are linked to the page. The slideshow has a body onload function: <body onload="showHot=true;self. focus()"; > and this is not allowing the match column heights script to work. I have tried adding both js scripts to the onload call, but that stops the slideshow from working correctly and allows the matching columns script to work. I used: <body onload="showHot=true;self. focus(); matchColumns=function()">. This was just a guess so I am probably mistaken. The webpage with slideshow is at www.sharonrieger.com.
Both javascript codes are below:
matchColumns=function(){
var divs,contDivs,maxHeight,di vHeight,d;
// get all <div> elements in the document
divs=document.getElementsB yTagName(' div');
contDivs=[];
// initialize maximum height value
maxHeight=0;
// iterate over all <div> elements in the document
for(var i=0;i<divs.length;i++){
// make collection with <div> elements with class attribute 'container'
if(/\bcolumn\b/.test(divs[ i].classNa me)){
d=divs[i];
contDivs[contDivs.length]= d;
// determine height for <div> element
if(d.offsetHeight){
divHeight=d.offsetHeight;
}
else if(d.style.pixelHeight){
divHeight=d.style.pixelHei ght;
}
// calculate maximum height
maxHeight=Math.max(maxHeig ht,divHeig ht);
}
}
// assign maximum height value to all of container <div> elements
for(var i=0;i<contDivs.length;i++) {
contDivs[i].style.height=m axHeight + "px";
}
}
// Runs the script when page loads
window.onload=function(){
if(document.getElementsByT agName){
matchColumns();
}
}
__________________________ __________ __________ __________ __
var SlideShowSpeed = 3000;
// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 2;
var Picture = new Array(); // don't change this
var Caption = new Array(); // don't change this
var Links = new Array();
var showHot = false; // don't change this
// Specify the image files...
// To add more images, just continue
// the pattern, adding to the array below.
// To use fewer images, remove lines
// starting at the end of the Picture array.
// Caution: The number of Pictures *must*
// equal the number of Captions!
Picture[1] = '/Images/slide-shows/home/ mens-retre at.jpg';
Picture[2] = '/Images/slide-shows/home/ webcast.jp g';
Picture[3] = '/Images/slide-shows/home/ PS.jpg';
Picture[4] = '/Images/slide-shows/home/ junior-pha risee.jpg' ;
Picture[5] = '/Images/slide-shows/home/ senior-hom e.jpg';
Picture[6] = '/Images/slide-shows/home/ couple-w-b ible.jpg';
Picture[7] = '/Images/slide-shows/home/ ABC-skit.j pg';
Picture[8] = '/Images/slide-shows/home/ give_me_Je sus.jpg';
Picture[9] = '/Images/slide-shows/home/ puppets.jp g';
Picture[10] = '/Images/slide-shows/home/ broadcasts .jpg';
// Specify the Captions...
// To add more captions, just continue
// the pattern, adding to the array below.
// To use fewer captions, remove lines
// starting at the end of the Caption array.
// Caution: The number of Captions *must*
// equal the number of Pictures!
Caption[1] = "Conferences/Events";
Caption[2] = "Webcasts";
Caption[3] = "Video Clips";
Caption[4] = "Guest Preaching";
Caption[5] = "Community Service";
Caption[6] = "Devotionals";
Caption[7] = "Drama/Comedy";
Caption[8] = "Christian Music";
Caption[9] = "Children/Puppets";
Caption[10] = "Broadcast/Radio";
// Specify the URL
Links[1] = "/HTML/conferences-events. html";
Links[2] = "/HTML/Multimedia/webcasts .html";
Links[3] = "/HTML/Multimedia/videos.h tml";
Links[4] = "/HTML/guest-preaching.htm l";
Links[5] = "/HTML/community-service.h tml";
Links[6] = "/HTML/Devotionals/devotio nals.html" ;
Links[7] = "/HTML/drama.html";
Links[8] = "/HTML/Multimedia/music.ht ml";
Links[9] = "/HTML/children-entertainm net.html";
Links[10] = "/HTML/Multimedia/broadcas ts-Christi an.html";
// ========================== ========== =
// Do not edit anything below this line!
// ========================== ========== =
var tss;
var iss;
var jss = 0;
var pss = Picture.length-1;
var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = Picture[iss];}
function control(how){
if (showHot){
if (how=="H") jss = 1;
if (how=="F") jss = jss + 1;
if (how=="B") jss = jss - 1;
if (jss > (pss)) jss=1;
if (jss < 1) jss = pss;
if (document.all){
document.images.PictureBox .style.fil ter="blend Trans(dura tion=2)";
document.images.PictureBox .style.fil ter="blend Trans(dura tion=Cross FadeDurati on)";
document.images.PictureBox .filters.b lendTrans. Apply();}
document.images.PictureBox .src = preLoad[jss].src;
if (document.getElementById) {
document.getElementById("C aptionBox" ).innerHTM L= Caption[jss];
document.getElementById("i mgLink").h ref= Links[jss];
}
if (document.all) document.images.PictureBox .filters.b lendTrans. Play();
}}
Also, using the forward and backwards button on the slideshow causes the pages to jump depending on your view. I know this is a tough question, and maybe I should ask about the jumping issue in a separate question. But I thought they might be related. If not, I will post them separately.
Thanks for considering my issues.
alabina
Both javascript codes are below:
matchColumns=function(){
var divs,contDivs,maxHeight,di
// get all <div> elements in the document
divs=document.getElementsB
contDivs=[];
// initialize maximum height value
maxHeight=0;
// iterate over all <div> elements in the document
for(var i=0;i<divs.length;i++){
// make collection with <div> elements with class attribute 'container'
if(/\bcolumn\b/.test(divs[
d=divs[i];
contDivs[contDivs.length]=
// determine height for <div> element
if(d.offsetHeight){
divHeight=d.offsetHeight;
}
else if(d.style.pixelHeight){
divHeight=d.style.pixelHei
}
// calculate maximum height
maxHeight=Math.max(maxHeig
}
}
// assign maximum height value to all of container <div> elements
for(var i=0;i<contDivs.length;i++)
contDivs[i].style.height=m
}
}
// Runs the script when page loads
window.onload=function(){
if(document.getElementsByT
matchColumns();
}
}
__________________________
var SlideShowSpeed = 3000;
// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 2;
var Picture = new Array(); // don't change this
var Caption = new Array(); // don't change this
var Links = new Array();
var showHot = false; // don't change this
// Specify the image files...
// To add more images, just continue
// the pattern, adding to the array below.
// To use fewer images, remove lines
// starting at the end of the Picture array.
// Caution: The number of Pictures *must*
// equal the number of Captions!
Picture[1] = '/Images/slide-shows/home/
Picture[2] = '/Images/slide-shows/home/
Picture[3] = '/Images/slide-shows/home/
Picture[4] = '/Images/slide-shows/home/
Picture[5] = '/Images/slide-shows/home/
Picture[6] = '/Images/slide-shows/home/
Picture[7] = '/Images/slide-shows/home/
Picture[8] = '/Images/slide-shows/home/
Picture[9] = '/Images/slide-shows/home/
Picture[10] = '/Images/slide-shows/home/
// Specify the Captions...
// To add more captions, just continue
// the pattern, adding to the array below.
// To use fewer captions, remove lines
// starting at the end of the Caption array.
// Caution: The number of Captions *must*
// equal the number of Pictures!
Caption[1] = "Conferences/Events";
Caption[2] = "Webcasts";
Caption[3] = "Video Clips";
Caption[4] = "Guest Preaching";
Caption[5] = "Community Service";
Caption[6] = "Devotionals";
Caption[7] = "Drama/Comedy";
Caption[8] = "Christian Music";
Caption[9] = "Children/Puppets";
Caption[10] = "Broadcast/Radio";
// Specify the URL
Links[1] = "/HTML/conferences-events.
Links[2] = "/HTML/Multimedia/webcasts
Links[3] = "/HTML/Multimedia/videos.h
Links[4] = "/HTML/guest-preaching.htm
Links[5] = "/HTML/community-service.h
Links[6] = "/HTML/Devotionals/devotio
Links[7] = "/HTML/drama.html";
Links[8] = "/HTML/Multimedia/music.ht
Links[9] = "/HTML/children-entertainm
Links[10] = "/HTML/Multimedia/broadcas
// ==========================
// Do not edit anything below this line!
// ==========================
var tss;
var iss;
var jss = 0;
var pss = Picture.length-1;
var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = Picture[iss];}
function control(how){
if (showHot){
if (how=="H") jss = 1;
if (how=="F") jss = jss + 1;
if (how=="B") jss = jss - 1;
if (jss > (pss)) jss=1;
if (jss < 1) jss = pss;
if (document.all){
document.images.PictureBox
document.images.PictureBox
document.images.PictureBox
document.images.PictureBox
if (document.getElementById) {
document.getElementById("C
document.getElementById("i
}
if (document.all) document.images.PictureBox
}}
Also, using the forward and backwards button on the slideshow causes the pages to jump depending on your view. I know this is a tough question, and maybe I should ask about the jumping issue in a separate question. But I thought they might be related. If not, I will post them separately.
Thanks for considering my issues.
alabina
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think the issue is that the onload in the body tag and the window.onload=function() in the Javascript are working against each other so I don't think that re-ordering them will work but I guess it is worth a shot to find out.
Depending on how you attach your event handler, you can allow for multiple event handlers per event. Here is one approach:
http://novemberborn.net/javascript/event-cache
http://novemberborn.net/javascript/event-cache
>I think the issue is that the onload in the body tag and the window.onload=function() in the Javascript are working against each other so I don't think that re-ordering them will work but I guess it is worth a shot to find out.
You're right, I also think that's the issue, and what I said was indeed a wild guess, but I've just tested it and it seems to work (even with the window.onload still in the script, but of course that wouldn't be needed anymore then).
You're right, I also think that's the issue, and what I said was indeed a wild guess, but I've just tested it and it seems to work (even with the window.onload still in the script, but of course that wouldn't be needed anymore then).
Sorry, the link above is for tracking and removing eventhandlers to prevent memory leaks, not attaching multiple event handlers to a single event. Nevertheless, attaching multiple event handlers to a single event is possible; search Google for a few ways.
ASKER
I removed the window.onload function from the match column height script and that did the trick. I know, that is so simple, but I needed someone to point that out to me. I am just learning javascript so this is a good lesson for me.
Thanks
Thanks
<body onload="matchColumns(); showHot=true;self.focus();