html - Execute browser pagejavascript from a scriptcommand-line - Stack Overflow

Hope this isnt a stupid question.I have recently had an idea about something which I am very curious a

Hope this isnt a stupid question.
I have recently had an idea about something which I am very curious about.
I am a fan of Node.js (not really relevent here I think) and the V8 engine but I was wondering if its possible to run a browser (get it to execute JS) but INTERNALLY.

What I mean by that is to create a program (possibly using the V8 engine) which can open a page (as if in the browser) and execute its javascript.

For instance say I have the below file hosted on www.mysite.co.uk/home.php

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
//javascript AJAX call to www.mysite.co.uk/ping.php
}
myFunction();
</script>
</head>

<body>
</body>
</html>

And ping.php looks something like:

<?php
//connect mysql, database ping and table ping
//it is a single column table with integer value starting on 0
//increment by 1 and update the table

Say I wanted to get the Javascript to execute by using some sort of script on my mand line/linux box (essentially WITHOUT using a browser).

So something like:

./mybrowser .php

or even:

./mybrowser home.php

I feel like it should be possible as the V8 (or different JS engine) should technically be able to execute Javascript but I havnt the foggiest how it could do so out of a browser context (or even if its possible).

Any ideas?

Hope this isnt a stupid question.
I have recently had an idea about something which I am very curious about.
I am a fan of Node.js (not really relevent here I think) and the V8 engine but I was wondering if its possible to run a browser (get it to execute JS) but INTERNALLY.

What I mean by that is to create a program (possibly using the V8 engine) which can open a page (as if in the browser) and execute its javascript.

For instance say I have the below file hosted on www.mysite.co.uk/home.php

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
//javascript AJAX call to www.mysite.co.uk/ping.php
}
myFunction();
</script>
</head>

<body>
</body>
</html>

And ping.php looks something like:

<?php
//connect mysql, database ping and table ping
//it is a single column table with integer value starting on 0
//increment by 1 and update the table

Say I wanted to get the Javascript to execute by using some sort of script on my mand line/linux box (essentially WITHOUT using a browser).

So something like:

./mybrowser http://www.mysite.co.uk/home.php

or even:

./mybrowser home.php

I feel like it should be possible as the V8 (or different JS engine) should technically be able to execute Javascript but I havnt the foggiest how it could do so out of a browser context (or even if its possible).

Any ideas?

Share Improve this question edited Feb 28, 2013 at 10:09 Christophe Roussy 17.1k5 gold badges93 silver badges87 bronze badges asked Feb 28, 2013 at 9:19 Craig TaubCraig Taub 4,1791 gold badge21 silver badges25 bronze badges 2
  • 2 Do you mean a headless browser, like PhantomJS? – Teemu Commented Feb 28, 2013 at 9:24
  • yes a couple of google searches and could not find this...looks just the think....will give it a try and update ticket...thanks alot – Craig Taub Commented Feb 28, 2013 at 9:27
Add a ment  | 

2 Answers 2

Reset to default 5

You can use any js engine to run js scripts as long as they do not rely on the DOM.

You could start by looking at:

  • Running V8 Javascript Engine Standalone

Edit: as I understand you want a headless browser, here are some:

  • HTMLUnit (I use that one for unit testing)
  • PhantomJS
  • Zombie.js

Running JavaScript on the mand line by using either Rhino for Java or Windows Script Host.

http://www.mozilla/rhino/

http://msdn.microsoft./en-us/library/9bbdkx3k%28VS.85%29.aspx

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745438025a4627699.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信