无需使用 ActiveX 即可截取网站屏幕截图的 JavaScript 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2046812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript code to take a screenshot of a website without using ActiveX
提问by Jourkey
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.
我有一个用户与之交互的 JavaScript 应用程序。我需要保存当前时间的界面外观,裁剪出我需要的部分(或者通过指定div只拍摄我需要的部分),然后将其发送回服务器。
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?
显然,任何外部服务都无法做到这一点,我需要一个可以保存屏幕外观的 JavaScript(或Flash)脚本。这可能吗?
Also, as the comment below says, I cannot use ActiveX.
另外,正如下面的评论所说,我不能使用 ActiveX。
回答by JAAulde
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/
Google 正在 Google+ 中这样做,一位才华横溢的开发人员对其进行了逆向工程并生成了http://html2canvas.hertzen.com/。要在 IE 中工作,您需要一个画布支持库,例如http://excanvas.sourceforge.net/
回答by Michael Neale
I think using JavaScript, you won't be able to due to the security restrictions. Flash, possibly.
我认为使用 JavaScript,由于安全限制,您将无法使用。闪光,可能。
回答by YOU
It's impossible in pure JavaScript, without using ActiveX.
在纯 JavaScript 中,不使用 ActiveX 是不可能的。
回答by Sug
It is impossible using JavaScript (nor Flash). It depends on your constraints, and there are some workarounds.
使用 JavaScript(或 Flash)是不可能的。这取决于您的限制条件,并且有一些解决方法。
- You can take advantage of browser extensions (such as a Firefox add-on), but I guess it does not fit your requierments.
- The best option I can think of is to construct the DOMtree on the client side, and then post it to remote server.
- 您可以利用浏览器扩展(例如 Firefox 附加组件),但我想它不符合您的要求。
- 我能想到的最佳选择是在客户端构建DOM树,然后将其发布到远程服务器。
On the server side nothing really holds you from doing generally anything. Using WebKitor even launching Internet Explorer or Firefox, you can create the snapshot server-side. It's far from elegant, but possible.
在服务器端,没有什么能真正阻止你做任何事情。使用WebKit甚至启动 Internet Explorer 或 Firefox,您可以创建快照服务器端。这远非优雅,但可能。

