www.webdeveloper.com
Results 1 to 3 of 3

Thread: html2canvas - take screenshot of a visible div and of a div with "display: none;"

  1. #1
    Join Date
    Apr 2013
    Posts
    5

    Exclamation html2canvas - take screenshot of a visible div and of a div with "display: none;"

    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:

    Code:
    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

  2. #2
    Join Date
    Apr 2013
    Posts
    5
    It seems that nobody has any clue about this or any ideas on how to fix it ?

    Hopefully I'm wrong about this...

    My best regards,
    Michael

  3. #3
    Join Date
    Mar 2011
    Posts
    1,108
    I haven't done much more than play with canvas for 5 minutes, but I suspect that the solution will require saving the id of the currently visible <div>, then sequentially making each one visible and saving it before finally restoring the original settings.
    Rick Trethewey
    Rainbo Design

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles