5 Replies - 1202 Views - Last Post: 15 May 2013 - 06:05 AM

#1 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 18-August 12

Using Phantomjs

Posted 10 May 2013 - 07:44 AM

I'm having issues with this phantomjs file. Very basic scripts I can execute in the console but when I take it a web page I'm getting either one of two error messages but both are undefined methods. I've tried using the require() and the WebPage().


Any help would be so appreciated
---Both result in Uncaught reference error: require is not defined---

Here is my code just something very plain to get started.

<!DOCTYPE html>
<html>

<head> <title> Phantom </title>

<style>
 #change_me {
 position: absolute;
 top: 100px;
 left: 400px;
 font: 24px arial;}
 #move_up #move_down #color #disappear {
 padding: 5px;}
</style>

<script src="scripts/jquery1.9.1.js"></script>
<script src="scripts/phantomjs.exe"> </script>

</head>
<body>

 <button id="move_up">Move Up</button>
 <button id="move_down">Move Down</button>
 <button id="color">Change Color</button>
 <button id="disappear">Disappear/Re-appear</button>

<div id="change_me">Make Me Do Stuff!</div>

<script>
$(document).ready(function() 
{
  $("#move_up").click( function() 
  {
  $("#change_me").animate({top:30},200);
  });//end move_up

  $("#move_down").click( function() {
  $("div").animate({top:500},2000);
  });//end move_down

  $("#color").click( function() {
  $("#change_me").css("color", "Red");
  });//end color

  $("#disappear").click( function() {
  $("#change_me").toggle("slow");
});//end disappear


});//end doc ready

console.log("hi");
</script>

<script>
var page = require('webpage').create();
page.open('http://google.com', function () {
    page.render('google.png');
    phantom.exit();
});


</script>

</body>
</html>




Is This A Good Question/Topic? 0
  • +

Replies To: Using Phantomjs

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: Using Phantomjs

Posted 10 May 2013 - 08:39 AM

I don't use phantom.js but I doubt that you can point to an executable in a script-tag(?):

<script src="scripts/phantomjs.exe"> </script>

I believe you have to add phantomjs.exe to your system's path, and run your script from the command-line:

phantomjs hello.js


https://github.com/a...iki/Quick-Start

This post has been edited by andrewsw: 10 May 2013 - 08:43 AM

Was This Post Helpful? 0
  • +
  • -

#3 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 18-August 12

Re: Using Phantomjs

Posted 10 May 2013 - 08:45 AM

Yea I've run it correctly from the command line a few times. I would like now to put a button on the web page that captures a screen shot of the current page. So I guess how do I code a button even to execute the phantomjs is what I'm still searching for.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Using Phantomjs

Posted 11 May 2013 - 03:19 AM

View Postandrewsw, on 10 May 2013 - 05:39 PM, said:

I don't use phantom.js but I doubt that you can point to an executable in a script-tag(?):

as long as that file returns valid Javascript code, it doesn’t matter which name or extension the file has. though in this case Windows’s default behaviour probably gets in the way.
Was This Post Helpful? 1
  • +
  • -

#5 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 18-August 12

Re: Using Phantomjs

Posted 13 May 2013 - 05:28 AM

Yea it was a long shot but at that point I was just trying anything to see how it would react. The goal is to create a button and on the click event it capture the screen image and save as a pdf but i'm hitting dead ends with my searches.
Was This Post Helpful? 0
  • +
  • -

#6 troyb408  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 18-August 12

Re: Using Phantomjs

Posted 15 May 2013 - 06:05 AM

Never mind thanks all after searching and trying I figured out how to get it working pretty slick features using phantomjs
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1