JavaScript code to take a screenshot of a website

2019-01-07 09:14发布

I have a JavaScript application that an user interacts with. I need to save the appearance of the interface at the current time, crop out the part that I need (or only shot the part that I need by specifying the div), and send it back to the server.

Clearly any external services would not be able to do this, I need a JavaScript (or Flash) script that can save the screen appearance. Is this possible?

Also, as the comment below says, I cannot use ActiveX.

4条回答
Bombasti
2楼-- · 2019-01-07 09:23

Google is doing this in Google+ and a talented developer reverse engineered it and produced http://html2canvas.hertzen.com/ . To work in IE you'll need a canvas support library such as http://excanvas.sourceforge.net/

查看更多
别忘想泡老子
3楼-- · 2019-01-07 09:35

I think using JavaScript, you won't be able to due to the security restrictions. Flash, possibly.

查看更多
叼着烟拽天下
4楼-- · 2019-01-07 09:41

It's impossible in pure JavaScript, without using ActiveX.

查看更多
贪生不怕死
5楼-- · 2019-01-07 09:42

It is impossible using JavaScript (nor Flash). It depends on your constraints, and there are some workarounds.

  1. You can take advantage of browser extensions (such as a Firefox add-on), but I guess it does not fit your requierments.
  2. The best option I can think of is to construct the DOM tree on the client side, and then post it to remote server.

On the server side nothing really holds you from doing generally anything. Using WebKit or even launching Internet Explorer or Firefox, you can create the snapshot server-side. It's far from elegant, but possible.

查看更多
登录 后发表回答