How to execute phantomjs file browser?

大兔子大兔子 提交于 2019-12-18 06:56:44

问题


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.


回答1:


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 communicate with a PhantomJS instance using HTTP GET/POST with Web Server module. HEre is a topic onInter Process Communication found on the Wiki.



来源:https://stackoverflow.com/questions/19675031/how-to-execute-phantomjs-file-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!