1

I have to write some javascript code to take screenshots of a webpage but without rendering it in the foreground.First of all is it possible?Do I need to use some external libraries?Please give me some ideas :)

CAFxX
  • 28,060
  • 6
  • 41
  • 66
py_script
  • 808
  • 2
  • 16
  • 38
  • possible duplicate of [Take Screenshot of Browser via JavaScript](http://stackoverflow.com/questions/3316193/take-screenshot-of-browser-via-javascript) – Diodeus - James MacFarlane Apr 06 '11 at 18:54
  • 1
    It's similar but the use case is different. Specifically, that guy needed a snapshot of the current state for support purposes, whereas this question is more about a preview screenshot. – jhocking Apr 06 '11 at 19:13

3 Answers3

2

If you're talking of doing it in Firefox chrome code (i.e. extensions/addons) there's a really easy way to do it. If you're talking about content code (i.e. webpages) you can do it as above but you have to ask permission first (i.e. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');).

CAFxX
  • 28,060
  • 6
  • 41
  • 66
1

What is this screenshot for? Depending on your needs you can do it directly on the server using one of these libraries:

http://code.google.com/p/wkhtmltopdf/

http://code.google.com/p/dompdf/

jhocking
  • 5,527
  • 1
  • 24
  • 38
  • I will give a link to the script and screenshot a page.Without opening a browser.Does it export only to pdf? – py_script Apr 06 '11 at 19:07
  • 1
    I'm not sure if those libraries support any formats besides pdf, but you can use ImageMagick to convert pdf to jpg or png. – jhocking Apr 06 '11 at 19:11
  • Ok, the file format of the screenshot is minor.I want to find a way to take it first. :) – py_script Apr 06 '11 at 19:27
-3

The only way to do it is via ActiveX, which of course only works on IE. See this SO question for examples of this:
Take a screenshot of a webpage with JavaScript?

Community
  • 1
  • 1
Joel Martinez
  • 46,929
  • 26
  • 130
  • 185