can't change div element to canvas using html2canvas in asp.net

zey

I use html2canvas and this is how I declare js files and css in Master Page

     <head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="Scripts/html2canvas.js" type="text/javascript"></script>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>

In My content page ,

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript">
    html2canvas(document.getElementById("mainDiv"), {
        onrendered: function (canvas) {
            document.body.appendChild(canvas);
        }
    });
</script>    
<div id="mainDiv" style="background-color: #CCFF66; border-style: solid; border-color: #000000;
    width: 300px; height: 300px;display:block">
</div>    

but it doesn't work with this code document.getElementById("mainDiv") , but when I change to document.body

 html2canvas(document.body, { 
        onrendered: function (canvas) {
            document.body.appendChild(canvas);
        }

It works , it append image to the bottom of body .
But I don't want to convert the whole body of my page .
I Just want to convert DIV to canvas .
How can I fix this issue ?

dreamweiver

dude, your missing the $(document).ready ( function () { ... }) statement in your asp page , hence its not initialised

  $(document).ready ( function () { 
      html2canvas(document.getElementById("mainDiv"), {
           onrendered: function (canvas) {
              document.body.appendChild(canvas);
           }
       });
   });

Happy Coding :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

From Dev

html2canvas capturing div image

From Dev

Textarea screenshot using Html2Canvas

From Dev

Print page using html2canvas

From Dev

Using html2canvas to render a highcharts chart to pdf doesn't work on IE and Firefox

From Dev

Can't create a canvas using HTML and Javascript

From Dev

Can't change language using session at runtime ASP.NET

From Dev

How to set custom file name when exporting html element to Png file using html2canvas in jquery?

From Dev

HTML Div convert into image with background image Html2canvas

From Dev

Can't get image to change on keypress on canvas

From Dev

change transparent color into white in html2canvas

From Dev

jQuery loop array with div content inside with html2canvas

From Dev

jQuery loop array with div content inside with html2canvas

From Dev

how to use html2canvas to save a div

From Dev

convert html with highcharts graph to image using html2canvas

From Dev

html2canvas doesn't get image full height

From Dev

html2canvas doesn't render image at top left

From Dev

Screenshoting MapBox using html2canvas creates a black jpg

From Dev

Saving Morris charts to image using HTML2CANVAS

From Dev

Saving Morris charts to image using HTML2CANVAS

From Dev

Can i change the image size inside a canvas element?

From Dev

Polygon on google maps taints canvas when using html2canvas

From Dev

Leaflet map polygon not shown on canvas when using html2canvas

From Dev

drawing a div element inside a canvas

From Dev

Can't get canvas element height to equal container height

From Dev

TypeScript and Html2Canvas?

From Dev

Using the canvas element in HTML5

From Dev

asp.net mvc5 : how to make Model Id hidden so that no one can change from browser using inspect element

From Dev

asp.net mvc5 : how to make Model Id hidden so that no one can change from browser using inspect element

Related Related

  1. 1

    How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

  2. 2

    html2canvas capturing div image

  3. 3

    Textarea screenshot using Html2Canvas

  4. 4

    Print page using html2canvas

  5. 5

    Using html2canvas to render a highcharts chart to pdf doesn't work on IE and Firefox

  6. 6

    Can't create a canvas using HTML and Javascript

  7. 7

    Can't change language using session at runtime ASP.NET

  8. 8

    How to set custom file name when exporting html element to Png file using html2canvas in jquery?

  9. 9

    HTML Div convert into image with background image Html2canvas

  10. 10

    Can't get image to change on keypress on canvas

  11. 11

    change transparent color into white in html2canvas

  12. 12

    jQuery loop array with div content inside with html2canvas

  13. 13

    jQuery loop array with div content inside with html2canvas

  14. 14

    how to use html2canvas to save a div

  15. 15

    convert html with highcharts graph to image using html2canvas

  16. 16

    html2canvas doesn't get image full height

  17. 17

    html2canvas doesn't render image at top left

  18. 18

    Screenshoting MapBox using html2canvas creates a black jpg

  19. 19

    Saving Morris charts to image using HTML2CANVAS

  20. 20

    Saving Morris charts to image using HTML2CANVAS

  21. 21

    Can i change the image size inside a canvas element?

  22. 22

    Polygon on google maps taints canvas when using html2canvas

  23. 23

    Leaflet map polygon not shown on canvas when using html2canvas

  24. 24

    drawing a div element inside a canvas

  25. 25

    Can't get canvas element height to equal container height

  26. 26

    TypeScript and Html2Canvas?

  27. 27

    Using the canvas element in HTML5

  28. 28

    asp.net mvc5 : how to make Model Id hidden so that no one can change from browser using inspect element

  29. 29

    asp.net mvc5 : how to make Model Id hidden so that no one can change from browser using inspect element

HotTag

Archive