最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to execute phantomjs file browser? - Stack Overflow

programmeradmin0浏览0评论

I'm new to phantomJs. I've installed phantomjs in my system(Ubuntu) and executed a sample code "test.js" in terminal like,

test.js:

console.log("WELCOME TO PHANTOMJS");
phantom.exit();

In terminal

phantomjs test.js

its executed fine shows expected output.

NOw my question is, Is there any possibilites to execute above js file in a browser by importing that js file in a html file like,

<script src="test.js".....></script>

If is it possible means how to do?? Please help me.

I'm new to phantomJs. I've installed phantomjs in my system(Ubuntu) and executed a sample code "test.js" in terminal like,

test.js:

console.log("WELCOME TO PHANTOMJS");
phantom.exit();

In terminal

phantomjs test.js

its executed fine shows expected output.

NOw my question is, Is there any possibilites to execute above js file in a browser by importing that js file in a html file like,

<script src="test.js".....></script>

If is it possible means how to do?? Please help me.

Share Improve this question asked Oct 30, 2013 at 6:07 user2810903user2810903 711 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Short Version

You can't

Detailed Version

In its current state, PhantomJS is a standalone process and needs to have the full control (in a synchronous matter) over everything: event loop, network stack, and JavaScript execution, ... yes you write scripts in Javascript but it's simply because it exposes a JavaScript API (also for coffee script).

"How to execute a nodejs module in browser?" It's pretty the same problem and you simply can't because of phantomjs/nodejs dependencies : what is webpage module in your favorite the browser ? But it's still possibe to share pure JS library.

So, you can't directly reference a phantomjs script in your browser, but you can municate with a PhantomJS instance using HTTP GET/POST with Web Server module. HEre is a topic onInter Process Communication found on the Wiki.

发布评论

评论列表(0)

  1. 暂无评论