Capture screenshot of iframe - html2canvas not wor

2019-02-25 15:20发布

问题:

I have the following iframe:

<iframe name="content" src="" style="position: absolute; left: 0px; top: 28px;" allowtransparency="true" border="0" scrolling="yes" width="100%" frameborder="0" height="90%" id="MyFrame"></iframe>

I simply want to capture a screenshot of the iframe contents as they stand, I've tried html2canvas but it doesn't seem to work. I've tried placing the iframe inside a div but no joy.

I've seen various methods of achieving this using php, but nothing that seems clear. Can anyone shed any light?

回答1:

It's written in the limitations section of the doc: http://html2canvas.hertzen.com/documentation.html#limitations.

The script doesn't render plugin content such as Flash or Java applets. It doesn't render iframe content either.

Screen capture using JS raises security problems.

Recently I've been trying carota (https://github.com/danielearwicker/carota) with some success to render HTML text on a canvas. However, it only handles a small subset of HTML.

There is also the SVG foreignobjectapproach which makes it possible to render DOM objects in a canvas: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Drawing_DOM_objects_into_a_canvas

Unfortunately, it is not implemented in IE, including IE 11.