tags:

views:

10382

answers:

8

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?

+1  A: 

You can achieve that using HTA and vbscript. Just call an external tool to do the screenshotting. I forgot what the name is, but on Vista there is a tool to do screenshots. You don't even need an extra install for it.

As for as automatic - totally depends on the tool you use. If it has an API, I am sure you can trigger the screenshot and saving process through a couple VB calls without the user knowing that you did what you did.

Since you mentioned HTA, I am assuming you are on Windows and (probably) know your environment (e.g. OS and version) very well.

Till
+1  A: 

is there are particular reason why you want to use javascript & send it back to the server? If you want to see your website rendered by different browsers, you could use http://browsershots.org/

Peter
+1  A: 

We had a similar requirement for reporting bugs. Since it was for Intranet scenario, we were able to use browser addons (like Fireshot for Firefox, IE Screenshot for IE)

Gulzar
A: 

re the user design step - Have you considered something like http://www.balsamiq.com/products/mockups ?

Peter
I appreciate your answer and I'm familiar with balsamiq but that isn't what I want, it is to be integrated with an ERP.
Scott Bennett-McLeish
+9  A: 

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.

Joel Anair
+1 for the send the dom nodes to server bit
Allen
I agree with Allen, that's an ingenious way to potentially screenshot a page!
Ricket
+3  A: 

This might not be the ideal solution for you but might still be worth mentioning. Snapsie is an open source, ActiveX object that enables Internet Explorer screenshots to be captured and saved. Once the dll is registered on the client, you should be able to capture the screenshot and upload the file to the server withing javascript. Drawbacks: needs to register the dll at the client and works only with IE.

nikhil
A: 

The SnapEngage uses Java Applet (1.5+) to make a browser screenshot. AFAIK java.awt.Robot should do the job - the user has just to permit the applet to do it (once).

And I have just found a post about it:

xmedeko
+3  A: 

Pounder's if this is possible to do by setting the whole body elements into a canvase then using canvas2image ?

http://www.nihilogic.dk/labs/canvas2image/

RobertPitt