javascripthtawebpage-screenshot

Take a screenshot of a webpage with JavaScript?


Is it possible to to take a screenshot of a webpage with JavaScript and then submit that back to the server?

I'm not so concerned with browser security issues. etc. as the implementation would be for HTA. But is it possible?


Solution

  • 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:

    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.