I don’t even know what a memory leak is….but I know I have certainly created one….in IE7 anyway. Safari, Opera, and FF work fine.
The page: [url]http://www.horizonconference.org/samplealbum.php
Click on a picture to bring up the picture div. I have created a JS function that switches the next and previous images by using your arrow keys. In the source code in [url]http://www.horizonconference.org/js/albums.js
[code]
function swapPhoto(e) {
var found = false;
//first determine if the window is open – if it isn’t then remove the event listener ond do nothing
if(xGetElementById(“photoWindowDiv”)) {
//get all children elements and make sure one of them is display: block
theDivs = xGetElementById(“photoWindowDiv”).getElementsByTagName(“div”);
for(i=0;i<theDivs.length;i++) {
if(theDivs[i].parentNode.id == “photoWindowDiv”) {
if(theDivs[i].style.display == “block”) {
found = theDivs[i];
break;
}
}
}
var next;
var prev;
if(found) {
var ev=(!e)?window.event:e;//IE:Moz
//get the next and previous values
nextprev = found.getElementsByTagName(“span”);
for(i=0;i<nextprev.length;i++) {
switch(nextprev[i].className) {
case “next”: next = nextprev[i].innerHTML; break;
case “prev”: prev = nextprev[i].innerHTML; break;
}
}
switch(ev.keyCode) {
case 37: showPhoto(prev); break;
case 39: showPhoto(next); break;
}
}
}
if(!found) {
xRemoveEventListener(document,’keydown’,keypress,false);
}
}
Basically what it does is it determines first if an image is being displayed on the screen. Sometimes this onkeydown event might be fired when there isn’t any need for it and if that’s the case I remove it at the bottom by the if(!found) statement.
Then it will find the next and previous photo ids which are stored in the DOM and then call a function using those values depending on what key was pushed.
When you do it in FF, everything works great and you can actually scroll through the photos pretty fast by holding your finger down on one of the arrow keys. In IE7 however, it gets slower and slower and slower every time you push an arrow key. I have no idea how to find the “leak” and I am hoping some experts can help me out. Thanks.