I used to do this in a project called friendsmap.biz (this project shows you a Google Map with your Facebook friends). By now, the page is broken (Facebook updated its API, and I haven't had time to update the project). Yesterday I had a long discussion with my boss about the need to take a snapshot of a dynamic element (let's call it a graph or a map, anything that is dynamically created on the user end with javascript). To make this possible, I found the html2canvas project. Here is what I did.
- Download the javascript of html2canvas, and include it in your HTML
<script src="/html2canvas.min.js" type="text/javascript"></script>
- Put a DIV tag and use the id property to name it.
<div id='map-canvas'><!-- your magic here --></div>
- Include this routine
<script>
function saveMapToDataUrl() {
var element = document.getElementById('map-canvas');
if (
((get_browser() == "Safari") && (get_browser_version() > 535)) ||
((get_browser() != "Safari") && (get_browser() != "Opera"))){
formPost.append("locale", "en_CA");
});
}
html2canvas(element, {
}
});
}
</script> - Do your additional javascript coding to call the routine. Remember javascript is asynchronous in many ways, so you will need to deal with that in your way. You will need the html2canvasproxy.php script especially if you are doing cross-site scripts.
Enjoy!