I am establishing a HttpUrlConnection
with a webpage . Now I have javascript
snippet that I want to execute on this webpage . How can I do this ?
Asked
Active
Viewed 1,871 times
0

Donotello
- 157
- 2
- 2
- 14
-
2javascript gets executed in a browser, so you could use a browser automatisation framework like for example webdriver/selenium – donfuxx Mar 28 '14 at 15:05
-
Do you control the webpage? You cannot execute script directly, as JavaScript is executed client side, but you could code something that listens for incoming connections. – Evan Knowles Mar 28 '14 at 15:06
-
this is my website . i control it . but i wanted to execute javascript on it as a client . – Donotello Mar 28 '14 at 15:08
-
http://stackoverflow.com/questions/247483/http-get-request-in-javascript is this what you looking for? – Prakash Mar 28 '14 at 15:09
2 Answers
2
You could try :
private static ScriptEngineManager mgr = null;
private static ScriptEngine engine = null;
mgr = new ScriptEngineManager();
engine = mgr.getEngineByName("JavaScript");
Object eval = engine.eval(s); // s is javascript code

TheWalkingCube
- 2,036
- 21
- 26
1
Since Javascript needs some kind of Virtual Machine to run in - usually provided by browsers or programms which act like browsers (so called headless browsers), you have to use some kind of "browsing engine" (so to say) to run the page in. Perhaps WebEngine may be worth a look.

Thomas Junk
- 5,588
- 2
- 30
- 43