Zetknąłem się z takim problemem:
Stworzyłem skrypt w javascriptcie, który odpowiada za "slideshow" i przełączanie obrazków w galerii zdjęć. Zauważyłem, że gdy wejdę na stronę z tym skryptem na localhoście przez IE7, Apache nagle zaczyna zabierać 100% zasobów procesora. Gdy zmienię stronę, Apache NADAL zabiera 100%

Pewnie źle napisałem skrypt pod ie7...
W innych przeglądarkach ok (opera, FF, ie6)
Oto prosty kod java script:
Kod
function setPic() {
document.pic.src=Galimg[newPic]
refreshCounter()
}
function preLoad() {
if(newPic < totalPic) {
newPicBuffer = newPic + 1
bufferdone = false
GRSKEZ = new Image
GRSKEZ.src = Galimg[newPicBuffer]
}
}
function checkLOAD(bztk) {
bufferdone = false
if(bztk.complete) {
bufferdone = true
} else {
setTimeout("checkLOAD('" + bztk + "')", 100)
}
}
function nextPic() {
if(newPic < totalPic) {
newPic++
setPic()
preLoad()
}
}
function prevPic() {
if(newPic != 1) {
newPic--
setPic()
}
}
function refreshCounter() {
document.getElementById("imgData").innerHTML = Desimg[newPic];
if(newPic == 1) { document.getElementById('prev').disabled=true } else { document.getElementById('prev').disabled=false }
if(newPic == totalPic) { document.getElementById('next').disabled=true } else { document.getElementById('next').disabled=false }
}
function cyclePic() {
setTimeout("cycle()", 10*1000)
}
function cycle() {
if(!stopIT) {
if(isImageOk()) {
if (newPic == totalPic) {
newPic = 0
stopIT=true
document.getElementById('play').disabled=false
document.getElementById('stop').disabled=true
}
nextPic()
cyclePic()
} else {
setTimeout("cycle()", 1000)
}
}
}
function isImageOk() {
// During the onload event, IE correctly identifies any images
// that weren't downloaded as not complete. Others should too.
// Gecko-based browsers act like NS4 in that they report this
// incorrectly: they always return true.
if (!document.images.pic.complete) {
return false;
}
// However, they do have two very useful properties: naturalWidth
// and naturalHeight. These give the true size of the image. If
// it failed to load, either of these should be zero.
if (typeof document.images.pic.naturalWidth != "undefined" && document.images.pic.naturalWidth == 0) {
return false;
}
// No other way of checking: assume it's ok.
return true;
}
function keyboardAction(e) {
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
key = String.fromCharCode(keycode).toLowerCase();
if((key == 'x')){ // end the cycle
stopIT=true;
document.getElementById('play').disabled=false;
document.getElementById('stop').disabled=true;
} else if(key == ',' || key == 'p' || key == 'c'){ // display previous image
prevPic();
} else if(key == '.' || key == 'n' || key == 'v'){ // display next image
nextPic();
} else if(key == 'z'){ // start cycle
if(stopIT) {
stopIT = false;
document.getElementById('play').disabled=true;
document.getElementById('stop').disabled=false;
setTimeout('cycle()', 2*1000);
}
}
}
document.pic.src=Galimg[newPic]
refreshCounter()
}
function preLoad() {
if(newPic < totalPic) {
newPicBuffer = newPic + 1
bufferdone = false
GRSKEZ = new Image
GRSKEZ.src = Galimg[newPicBuffer]
}
}
function checkLOAD(bztk) {
bufferdone = false
if(bztk.complete) {
bufferdone = true
} else {
setTimeout("checkLOAD('" + bztk + "')", 100)
}
}
function nextPic() {
if(newPic < totalPic) {
newPic++
setPic()
preLoad()
}
}
function prevPic() {
if(newPic != 1) {
newPic--
setPic()
}
}
function refreshCounter() {
document.getElementById("imgData").innerHTML = Desimg[newPic];
if(newPic == 1) { document.getElementById('prev').disabled=true } else { document.getElementById('prev').disabled=false }
if(newPic == totalPic) { document.getElementById('next').disabled=true } else { document.getElementById('next').disabled=false }
}
function cyclePic() {
setTimeout("cycle()", 10*1000)
}
function cycle() {
if(!stopIT) {
if(isImageOk()) {
if (newPic == totalPic) {
newPic = 0
stopIT=true
document.getElementById('play').disabled=false
document.getElementById('stop').disabled=true
}
nextPic()
cyclePic()
} else {
setTimeout("cycle()", 1000)
}
}
}
function isImageOk() {
// During the onload event, IE correctly identifies any images
// that weren't downloaded as not complete. Others should too.
// Gecko-based browsers act like NS4 in that they report this
// incorrectly: they always return true.
if (!document.images.pic.complete) {
return false;
}
// However, they do have two very useful properties: naturalWidth
// and naturalHeight. These give the true size of the image. If
// it failed to load, either of these should be zero.
if (typeof document.images.pic.naturalWidth != "undefined" && document.images.pic.naturalWidth == 0) {
return false;
}
// No other way of checking: assume it's ok.
return true;
}
function keyboardAction(e) {
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
key = String.fromCharCode(keycode).toLowerCase();
if((key == 'x')){ // end the cycle
stopIT=true;
document.getElementById('play').disabled=false;
document.getElementById('stop').disabled=true;
} else if(key == ',' || key == 'p' || key == 'c'){ // display previous image
prevPic();
} else if(key == '.' || key == 'n' || key == 'v'){ // display next image
nextPic();
} else if(key == 'z'){ // start cycle
if(stopIT) {
stopIT = false;
document.getElementById('play').disabled=true;
document.getElementById('stop').disabled=false;
setTimeout('cycle()', 2*1000);
}
}
}
Używam go tak:
Przez php podaję parametry do galerii, w jednej tablicy daję listę urlów do zdjęć, a w drugiej opis do zdjęć.
Kod
var Galimg = new Array();
var Desimg = new Array();
var bufferdone = true;
var newPic = 2
var totalPic = 18
var stopIT = true
var Desimg = new Array();
var bufferdone = true;
var newPic = 2
var totalPic = 18
var stopIT = true
No i tylko jeszcze:
<body onLoad="preLoad();refreshCounter();document.onkeydown = keyboardAction; ">
Próbowałem w nim zawrzeć mechanizm cachujący do galerii i być może w nim tkwi problem :/
Sam nie wiem, do którego działu to dać... czy to bug IE7 czy mój javascriptowy błąd. Proszę moderatorów o podjęcie decyzji
