0

I have got a javascript code to capture screenshot from the given url.I found the demo of it too.. But i don't know how to add this to my website. Can someone pls help me

http://ctrlq.org/code/19136-screenshots-javascript

var system = require('system');

// Web Address (URL) of the page to capture
var url  = system.args[1];

// File name of the captured image
var file = system.args[2]  + ".png";

var page = require('webpage').create();

// Browser size - height and width in pixels
// Change the viewport to 480x320 to emulate the iPhone
page.viewportSize = { width: 1200, height : 800 };

// Set the User Agent String 
// You can change it to iPad or Android for mobile screenshots
page.settings.userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";

// Render the screenshot image
page.open ( url, function ( status ) {
  if ( status !== "success") {
       console.log("Could not open web page : " + url);
       phantom.exit();
   } else {
       window.setTimeout ( function() {
          page.render(file);
          console.log("Download the screenshot : " + file);
          phantom.exit();
       }, 1000);
   }
});`
alex
  • 479,566
  • 201
  • 878
  • 984

2 Answers2

0

This isn't standard Javascript, it's Phantomjs, headless Webkit programmable with Javascript. You can't put it on your page, however you can run it on your server and provide a service to your users through an API of sorts.

If you want to screenshot your page on the client end use Html2canvas.

Etheryte
  • 24,589
  • 11
  • 71
  • 116
  • how can I use html2canvas. Is that a html5 function? How can I add it to my site? –  Mar 07 '14 at 04:54
  • @user3313594 Added a link to the answer. It's a Javascript script, see the link for details, you include it in your page. And just so we're in the clear, HTML (and HTML5 as its subset) aren't programming languages and don't strictly have functions. – Etheryte Mar 07 '14 at 08:02
  • sir, i have checked it. But i couldn't understand its documentation. Their example/test seem to be great. I only know html and php. How can i add it to my site?? –  Mar 07 '14 at 09:15
  • To use Html2canvas, I recommend you to learn the basics of JavaScript first. Don't be scared of it, it gets quite easy once you get through the beginning. I'd like to point you to this question: http://stackoverflow.com/questions/11246/best-resources-to-learn-javascript – Bart Burg Mar 07 '14 at 09:43
0

You can also check this question & answer, it's about how to use HTML5 canvas to take a screenshot of the webpage.

Community
  • 1
  • 1
Bart Burg
  • 4,786
  • 7
  • 52
  • 87