题意:
用 JavaScript 截取网页截图?
问题背景:
Is it possible to to take a screenshot of a webpage with JavaScript and then submit that back to the server?
是否可以用 JavaScript 截取网页截图,然后将其提交回服务器?
I'm not so concerned with browser security issues. etc. as the implementation would be for HTA. But is it possible?
由于这个实现是针对 HTA(HTML 应用程序)的,我并不太担心浏览器安全问题等。但这是否可行呢?
问题解决:
I have done this for an HTA by using an ActiveX control. It was pretty easy to build the control in VB6 to take the screenshot. I had to use the keybd_event API call because SendKeys can't do PrintScreen. Here's the code for that:
我在 HTA(HTML 应用程序)中通过 ActiveX 控件实现了这一功能。用 VB6 构建截取屏幕的控件相当容易。由于 SendKeys 方法无法模拟 PrintScreen 键,我不得不使用 keybd_event API 调用。以下是相关代码:
Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const CaptWindow = 2
Public Sub ScreenGrab()
keybd_event &H12, 0, 0, 0
keybd_event &H2C, CaptWindow, 0, 0
keybd_event &H2C, CaptWindow, &H2, 0
keybd_event &H12, 0, &H2, 0
End Sub
That only gets you as far as getting the window to the clipboard.
这只能帮你把窗口内容复制到剪贴板中。
Another option, if the window you want a screenshot of is an HTA would be to just use an XMLHTTPRequest to send the DOM nodes to the server, then create the screenshots server-side.
另一种选择是:如果需要截图的窗口是 HTA(HTML 应用程序),可以通过 XMLHTTPRequest 将 DOM 节点发送到服务器,然后在服务器端生成截图。