PDA

View Full Version : html2canvas - take screenshot of a visible div and of a div with "display: none;"



mihailmrom
06-08-2013, 02:02 AM
Hello guys,

I need some advice about a issue I'm dealing with for the past 2 days

I trying to take a screenshot of a specific div which holds a couple of images that change every refresh.
I've managed to do that, using the following script - html2canvas (link: http://html2canvas.hertzen.com/)

Now, the script works just perfect until a specific point...

I have 2 div elements called "Tab_1" and "Tab_2", and both of them are been displayed using another .js script (for creating tabs).
Actualy, the tabs are created using the CSS-display options (the active one has "display: block;" - and the inactive one has "display: none;")

This is where the html2canvas script kinda fails....
It will take a screenshot of the images under the <div> tag which has the attribute "display: block" (the active tab) but it will not take a screenshot of the image under the <div> tag which has the attribute "display: none" (the inactive tab)

Basically this is my issue...

I want to call the function and be able to take the screenshot of both tabs (the active and the inactive)

Below is the script i'm working one:

function saveModel(usermamePic, firstPic, secondPic) {
var first_elm = document.getElementById(firstPic);
var second_elm = document.getElementById(secondPic);

html2canvas([first_elm],{
onrendered: function(canvas) {
var dataUrl_tabActive = canvas.toDataURL();
$.post('phpinclude/save.php',
{'encoded_img': ''+ dataUrl_tabActive +'',
'username_img': ''+ usermamePic +'',
'location_img': 'tabActive'
},
function(img) {
alert(img);
html2canvas([second_elm],{
onrendered: function(canvas) {
var dataUrl_tabInactive = canvas.toDataURL();
$.post('phpinclude/model_save.php',
{'encoded_img': ''+ dataUrl_tabInactive +'',
'username_img': ''+ usermamePic +'',
'location_img': 'tabInactive'
},
function(img) {
alert(img);
});
}
});
});
}
});
}


+ the html2canvas.js from the webpage shown above.

Any help will be appreciated!

My best regards,
Michael

mihailmrom
06-14-2013, 12:40 PM
It seems that nobody has any clue on how to fix this ?
Or any ideas on this subject ?

Hopefully I'm wrong about this :)

My best regards,
Michael

traq
06-14-2013, 04:43 PM
It will take a screenshot of the images under the <div> tag which has the attribute "display: block" (the active tab) but it will not take a screenshot of the image under the <div> tag which has the attribute "display: none" (the inactive tab)

Sure it will. But keep in mind that it will be a blank image.

display: none means just that: "not displayed." If you want to see that div (for any reason), you'll need to change that (e.g., to display: block) first.