Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html2canvas screenshot of external website

I don't have even any idea how to do this and the documentation of html2canvas is not really helpful at this part.

I'm able to make a screenshot of my html with this little piece of code:

target = $('#myDiv');
        html2canvas( target, {
        onrendered: function( canvas ) {
            /* canvas is the actual canvas element, 
               to append it to the page call for example 
             */
               document.body.appendChild( canvas );
            }
        })

but i want to be able to pass an url and make a screenshot of this page. Like they do in their example page on: http://html2canvas.hertzen.com/screenshots.html

If anyone could give me a hint how to get started with that, I would be really glad.

like image 214
movsky Avatar asked Oct 22 '25 21:10

movsky


1 Answers

You can't, for security reasons, load just any external URL. That's why, as they described on the page you linked to, you need to set up a separate server-side script that fetches the page. You then use that script, either directly or via AJAX, to provide the input for html2canvas.

like image 167
DNS Avatar answered Oct 24 '25 12:10

DNS