如何执行phantomjs文件浏览器? [英] How to execute phantomjs file browser?
问题描述
我是phantomJs的新手。我在我的系统(Ubuntu)中安装了phantomjs并在终端中执行了一个示例代码test.js,如
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(欢迎来到PHANTOMJS);
phantom.exit();
console.log("WELCOME TO PHANTOMJS");
phantom.exit();
在终端
phantomjs test.js
phantomjs test.js
其执行的罚款显示预期的输出。
its executed fine shows expected output.
我的问题是,是否有任何可能在js文件上面执行在浏览器中通过在html文件中导入该js文件,例如,
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>
<script src="test.js".....></script>
如果有可能意味着怎么办?请帮助我。
If is it possible means how to do?? Please help me.
推荐答案
短版
你不能
Short Version
You can't
在当前状态下,PhantomJS是一个独立的过程,需要完全控制(在同步问题中:事件循环,网络堆栈和JavaScript执行,...是的,您在Javascript中编写脚本,但这仅仅是因为它公开了JavaScript API(也用于咖啡脚本)。
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).
如何在浏览器中执行nodejs模块?这是相同的问题,你根本不能因为phantomjs / nodejs依赖:你最喜欢的浏览器中的网页
模块是什么?但它仍然可以共享纯JS库。
"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.
因此,您无法在浏览器中直接引用phantomjs脚本,但您可以使用HTTP与PhantomJS实例进行通信使用 Web服务器模块进行GET / POST。 HEre是关于Wiki上进程间通信的主题。
So, you can't directly reference a phantomjs script in your browser, but you can communicate with a PhantomJS instance using HTTP GET/POST with Web Server module. HEre is a topic onInter Process Communication found on the Wiki.
这篇关于如何执行phantomjs文件浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!