GrabzIt
Tools to Capture and Convert the Web

How to save a JavaScript Screenshot?

It is possible to save a JavaScript screenshot, but you will need to use one of our server side API's such as the PHP GetResult method to implement a small web service to save the image on the server side. An example PHP web service to save the screenshot, is shown below.

include("GrabzItClient.class.php");

$id = $_GET["id"];

// Custom id can be used to store user ids or whatever is needed for the later processing of the
// resulting screenshot

$grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$result = $grabzIt->GetResult($id);

if (!$result)
{
   return;
}

//assuming jpg screenshots
file_put_contents("results" . DIRECTORY_SEPARATOR . $id + ".jpg", $result);

To integrate the PHP web service with the JavaScript API you will need to use the OnFinish Event. This can then be used to make an AJAX call to the server side web service, which will contain the ID of the completed screenshot. The web service can then use this information to save the image on the web server. Note that the below example uses jQuery.

<script type="text/javascript">
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.google.com", 
    {"onfinish": "loaded"}).Create();

function loaded(id)
{
    $.ajax("http://www.example.com/mywebservice.php?id="+id);
}
</script>

Use the Data URI method instead

An alternative method is to use the DataURI method in the JavaScript Library to get the data URI of the capture this value can then be posted to your server were you can then save the image.

<script type="text/javascript">
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.google.com").DataURI(callback);

function callback(dataUri)
{
    $.post("http://www.example.com/mywebservice.php", {data: dataUri});
}
</script>

Export a capture to a storage solution

Captures can be exported straight to Amazon S3, DropBox, FTP and WebDav once it has been generated by setting the export parameter. To do this you need to create an export URL and pass it to the JavaScript API.

<script type="text/javascript">
GrabzIt("Sign in to view your Application Key").ConvertURL("http://www.google.com", 
    {"export": "dropbox://"}).Create();
</script>

Where export URL's specify a username and password it is recommended that you create a user just for this task, so it will be easy to revoke access if required. Also as this is in JavaScript it can’t be hidden, however there are ways of obfuscating your JavaScript code.

Back to Support
Try all our premium features for free with a 7 day free trial. Then from $5.99 a month, unless cancelled.
  • More Captures
  • More Features
  • More API's
  • Bigger Scrapes
  • Bigger Screenshots
  • Bigger Everything
Start Free Trial