Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to capture screenshot in html using js or jquery [duplicate]

I'm need my clients be able to capture screenshot of any page of my website using button like this:

<button>Take screenshot</button>

I tried to use html2canvas but it's doesn't work properly for me because i have iframe's in my website and it's cause some session problems.

someone have solution for this?

i looked all over google and didn't found something that's helps me much.

like image 758
divelner Avatar asked Dec 14 '15 16:12

divelner


2 Answers

Web pages are not the best things to be "screenshoted", because of their nature; they can include async elements, frames or something like that, they are usually responsive etc...

For your purpose the best way is to use external api or an external service, I think is not a good idea to try doing that with JS.

You should try url2png

like image 120
Giacomo Torricelli Avatar answered Oct 15 '22 19:10

Giacomo Torricelli


Look at the html2canvas project. Their approach is that they create a representation of the page inside a canvas. They don't make an actual screenshot, but builds it based on the content on the page and the loaded stylesheet. It could be used on the entire body or just a specific element.

It is also really easy to use. Here is an example:

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

You can adapt it to your code relatively easy.

Take a look at their demo. Click on any of the buttons and then scroll to the bottom of the page.


like image 43
Itay Grudev Avatar answered Oct 15 '22 21:10

Itay Grudev