jscheuer1
07-09-2005, 09:16 AM
I've written a somewhat complex script that includes image rollovers for a snazzy looking interface as you mouse over options. It works fine in IE6. Also fine in Firefox except that at certain times when the images are being rolled over, Firefox will act like it is loading a page (disc spins, load progress bar gets pinned at full and stays highlighted). The images have already long ago been cached at this point, there are only two very small ones involved. I'm looking for a method (similar to document.close() or something) that I could use after each rollover to get Firefox to stop this nonsense or some insight into what might be causing it to happen in the first place. Any ideas? I'm afraid the code will not make much sense without the markup which, is extensive (link to demo follows code). The code may provide some sharp javascript guru with enough to spot what's causing this though, so here it is (the offending function appears to be 'swapImage'):
/* © John Davenport Scheuer */
var containerPage='3col.htm'
var masterList='page1.htm'
var midPlace='page2.htm'
var endBlank='page3.htm'
var endPlace='page4.htm'
var offArrow='bluearrow.gif'
var onArrow='whitearrow.gif'
function restoreA(){
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='clicked'||links[i].className=='oldClicked'){
links[i].className='list'
swapImage(links[i].innerHTML,offArrow)
}
}
}
function restoreB(){
parent.frame1.grayOut()
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='clicked'){
links[i].className='list'
swapImage(links[i].innerHTML,offArrow)
}
}
}
function grayOut(){
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='clicked'){
links[i].className='oldClicked'
}
}
}
function swapImage(elm,img){
var tmpStr=elm.substr(elm.indexOf('name='))
document.images['ar'+parseInt(tmpStr.substr(tmpStr.indexOf('ar')+2))].src=img
}
function init() {
if (location.href.indexOf(containerPage)!==-1)
init1();
else if (location.href.indexOf(masterList)!==-1)
init2();
else
init3();
}
function init1() {
if (frame1.location.href.indexOf(masterList)==-1)
frame1.location.replace(masterList);
if (frame2.location.href.indexOf(midPlace)==-1)
frame2.location.replace(midPlace);
if (frame3.location.href.indexOf(endBlank)==-1)
frame3.location.replace(endBlank)
}
function init2() {
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='list'){
links[i].onmouseover=function(){
swapImage(this.innerHTML,onArrow)
}
links[i].onmouseout=function(){
if (this.className=='list')
swapImage(this.innerHTML,offArrow)
}
links[i].onclick=function(){
restoreA();this.className='clicked';
swapImage(this.innerHTML,onArrow)
if (parent.frame3.location.href.indexOf(endBlank)!==-1)
parent.frame3.location.replace(endPlace);
parent.frame2.location.replace(this.href);return false
}
}
}
}
function init3() {
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='list'){
links[i].onmouseover=function(){
swapImage(this.innerHTML,onArrow)
}
links[i].onmouseout=function(){
if (this.className=='list')
swapImage(this.innerHTML,offArrow)
}
links[i].onclick=function(){
restoreB();this.className='clicked';
swapImage(this.innerHTML,onArrow)
parent.frame3.location.replace(this.href);return false
}
}
}
}
window.onload=init;
LINK (http://home.comcast.net/~jscheuer1/side/3col/3col.htm)
/* © John Davenport Scheuer */
var containerPage='3col.htm'
var masterList='page1.htm'
var midPlace='page2.htm'
var endBlank='page3.htm'
var endPlace='page4.htm'
var offArrow='bluearrow.gif'
var onArrow='whitearrow.gif'
function restoreA(){
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='clicked'||links[i].className=='oldClicked'){
links[i].className='list'
swapImage(links[i].innerHTML,offArrow)
}
}
}
function restoreB(){
parent.frame1.grayOut()
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='clicked'){
links[i].className='list'
swapImage(links[i].innerHTML,offArrow)
}
}
}
function grayOut(){
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='clicked'){
links[i].className='oldClicked'
}
}
}
function swapImage(elm,img){
var tmpStr=elm.substr(elm.indexOf('name='))
document.images['ar'+parseInt(tmpStr.substr(tmpStr.indexOf('ar')+2))].src=img
}
function init() {
if (location.href.indexOf(containerPage)!==-1)
init1();
else if (location.href.indexOf(masterList)!==-1)
init2();
else
init3();
}
function init1() {
if (frame1.location.href.indexOf(masterList)==-1)
frame1.location.replace(masterList);
if (frame2.location.href.indexOf(midPlace)==-1)
frame2.location.replace(midPlace);
if (frame3.location.href.indexOf(endBlank)==-1)
frame3.location.replace(endBlank)
}
function init2() {
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='list'){
links[i].onmouseover=function(){
swapImage(this.innerHTML,onArrow)
}
links[i].onmouseout=function(){
if (this.className=='list')
swapImage(this.innerHTML,offArrow)
}
links[i].onclick=function(){
restoreA();this.className='clicked';
swapImage(this.innerHTML,onArrow)
if (parent.frame3.location.href.indexOf(endBlank)!==-1)
parent.frame3.location.replace(endPlace);
parent.frame2.location.replace(this.href);return false
}
}
}
}
function init3() {
var links=document.getElementsByTagName('a');
for (var i =0; i<links.length ; i++){
if (links[i].className=='list'){
links[i].onmouseover=function(){
swapImage(this.innerHTML,onArrow)
}
links[i].onmouseout=function(){
if (this.className=='list')
swapImage(this.innerHTML,offArrow)
}
links[i].onclick=function(){
restoreB();this.className='clicked';
swapImage(this.innerHTML,onArrow)
parent.frame3.location.replace(this.href);return false
}
}
}
}
window.onload=init;
LINK (http://home.comcast.net/~jscheuer1/side/3col/3col.htm)