Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript将图像存储到不在chrome上工作的数组_Javascript_Jquery_Image_Google Chrome_Firefox - Fatal编程技术网

javascript将图像存储到不在chrome上工作的数组

javascript将图像存储到不在chrome上工作的数组,javascript,jquery,image,google-chrome,firefox,Javascript,Jquery,Image,Google Chrome,Firefox,我试图在服务器上生成一些图像,将它们存储到javascript中的数组中,并动态使用它们 我通过以下代码片段来实现这一点: imageArray = new Array(); for(var i=1; i<=51; i++){ imageArray[i] = new Image(); if(i<10){ imageArray[i].src = "<?php echo 'tmp/'.$_SESSION['token'].'/out';?>0"

我试图在服务器上生成一些图像,将它们存储到javascript中的数组中,并动态使用它们

我通过以下代码片段来实现这一点:

imageArray = new Array();
for(var i=1; i<=51; i++){
    imageArray[i] = new Image();
    if(i<10){
        imageArray[i].src = "<?php echo 'tmp/'.$_SESSION['token'].'/out';?>0" + i + ".bmp";
    }else{
        imageArray[i].src = "<?php echo 'tmp/'.$_SESSION['token'].'/out';?>" + i + ".bmp";
    }
}
稍后,我将它们作为javascript中的背景图像加载

for (var i = -3; i <= 3; i++) {
    var img = $('#imgdiv' + i).get(0);
    if (imageArray[+i + +image0] != undefined) {
        img.style.backgroundImage = 'url(' + imageArray[+i + +image0].src + ')';
    } else {
        img.style.backgroundImage = '';
    }
}
这在firefox中有效,但在chrome中,每次我设置背景图像时,它都是从服务器加载图像


是否有其他方法存储它们,因为我想在页面加载后删除它们?

可能与缓存有关。尝试发送带有缓存相关标题的图像,以便向客户端浏览器明确无需重新加载图像。除此之外,在缓存背景图像时,Chrome可能会独树一帜,虽然我的一般经验是相反的:它不会像我通常希望的那样重新加载背景图像。你只需要图像的路径,而不是所有这些src内容-因此,数组只是每个图像的路径。将图像的路径存储在数组中并不意味着它会将实际图像存储在该数组中。但是我如何用JavaScript存储图像呢?因为我在服务器上生成它们,不再需要它们了。