</body>
</html>
-Go ahead, try it! You don't even need a web-server. Just copy and
-paste this HTML into a file on your computer -- `/tmp/magic.html`,
-say -- and point your web-browser at it:
-`file:///tmp/magic.html`. Just like that, you have working
-metasearching.
-
+Go ahead, try it! Simply put the above in a file (e.g index.html),
+drop it into a folder accessible with an ordinary web-server (e.g Apache)
+and load it in your web browser (and no, usually, you can't just load the file
+directly from disk as some browsers, e.g Chrome, won't allow storing cookies).
+Just like that, you have working metasearching.
How the example works
---------------------
var file_png = system.args[2] || 'indexdata.png';
var timeout = system.args[5] ? system.args[5] : 0.2;
-if (system.args.length === 1) {
- console.log('Usage: screenshot.js <some URL> <file.png>');
+function usage (message) {
+ if (message) {
+ console.log(message + "\n");
+ }
+ console.log('Usage: screenshot.js <some URL> <file.png> <width px> <height px> <timeout sec>');
phantom.exit();
}
+if (system.args.length === 1) {
+ usage();
+}
+
+if (!file_png.match(/\.png$/)) {
+ usage("File name has no .png extension: '" + file_png + "'");
+}
+
+
// page.zoomFactor = 1.0;
page.viewportSize = {
width: system.args[3] ? system.args[3] : 1200,
phantom.exit();
}, timeout * 1000);
});
+
+// EOF