I have a problem rendering divs as images via html2canvas.
Here is my javascript code:
function saveImages(i)
{
html2canvas($("#page"+i), {
logging:true,
onrendered: function(canvas){
var url = canvas.toDataURL();
$.post("saveImage.php", {"path": url, "index":i}, function(data){
var p = Math.round(((i+1)/totalPages)*100);
$("#progressGraphical").css("width", p+"%");
if(p>=100){p = "fertig!"}else{p += "%";}
$("#progress").html((i+1)+"/"+totalPages+" Seiten gespeichert - "+p);
if(i<totalPages) saveImages(i+1);
});
}
});
}
$(document).ready(function(){
saveImages(0);
});
I had to work recursively because of the post-request done with jquery functions. The php file which is requested takes the base64 encoded url generated by the canvas.toDataUrl-Method, decodes it and saves it to a image file called "page0/1/2/.../n.png".
All this works fine - Until a total number of about 24 recursive calls is exceeded. If this is the case, then all the images generated by html2canvas(even the images before the 24th recursive call) are drawn blank. I already looked at the base64-encoded urls - And there are just two equal strings which alternate.
Where is the error?