Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
How to get an image of a div using html2canvas

I'm trying to use html2canvas to get an image of a div to the clipboard so that a user is able to then paste the image in an email or message chat. I've looked up multiple different ways of trying to do this but none of them are working for me.

The code I am using is below.

$(document).on("click", ".canvas-button", function (){
    var div = document.getElementById($(this).data("div"));
    var rect = div.getBoundingClientRect();

    var canvas = document.createElement("canvas");
    canvas.width = rect.width;
    canvas.height = rect.height;

    var ctx = canvas.getContext("2d");
    ctx.translate(-rect.left,-rect.top);

    html2canvas(div, {
        canvas:canvas,
        height:rect.height,
        width:rect.width,
        onrendered: function(canvas) {
            var image = canvas.toDataURL("impage/png");
            window.open(image);
            var pHtml = "<img src="+image+" />";
            $("#parent").append(pHtml);
        }
    });
});

This code is able to find the div but it doesn't give me the image of it. I'm not sure what to do from here. Any help is appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!