2013-03-29 25 views
0

我是新的堆栈溢出;但已经发现这里讨论的许多主题在Web应用程序的开发中非常有用。FireFox中的Canvas问题,在Chrome中工作正常

但是,这次我很难过。我在JavaScript中编写了一些简单的函数,以便在使用新的HTML5画布时添加撤消/重做功能。我写的代码在Chrome中运行良好,但在Firefox中不起作用;我想我已经将问题隔离到了将图像对象放入数组中的代码行(在Chrome中正常工作)。我研究过这一点,但我无法找到任何理由,为什么这在FireFox中不起作用。任何帮助将不胜感激。

function push() 
{ 
window.cStep++; 
    if (window.cStep < window.history.length) { window.history.length = window.cStep; } 
var imageData = window.context.getImageData(0, 0, canvas.width, canvas.height); 
alert(imageData); 
window.history[window.cStep] = imageData; 
    document.title = "Step [" +window.cStep + "] Of A Possible [" + (window.history.length -1) + "]"; 
} 

function undo() 
{ 
    if (window.cStep > 0) { 
    window.cStep--; 
    window.context.putImageData(window.history[window.cStep], 0, 0); 
    document.title = "Step [" +window.cStep + "] Of A Possible [" + (window.history.length -1) + "]"; 
    if(window.cStep ==0) 
    {document.getElementById('middle_centre_canvas').style.opacity = 0.6;} 
    else 
    {document.getElementById('middle_centre_canvas').style.opacity = 1;} 
    } 
    } 
    function redo() 
    { 
    if (window.cStep < window.history.length-1) { 
    window.cStep++; 
    window.context.putImageData(window.history[window.cStep],0,0); 
    document.title = "Step [" +window.cStep + "] Of A Possible [" + (window.history.length -1) + "]"; 
    if(window.cStep >0) 
    {document.getElementById('middle_centre_canvas').style.opacity = 1;} 
    } 
    } 
     function loadyLoader(){ 
    window.canvas = document.getElementById("canvas"); 
    window.context = window.canvas.getContext('2d'); 
    window.history = new Array(); 
    window.cStep = -1; 
    push(); 
     } 

回答

0

window.history是一个保留对象:http://www.w3schools.com/jsref/obj_history.asp。 尝试用window._history(或其他名称)替换所有发生的window.history

+0

简直不敢相信 - 现在感觉很好,谢谢!这一个让我陷入了数小时,以及大声笑。 – Trobi

相关问题