For example if you type in the browser bar javascript:alert('hai'); it shows a pop up. Is that possible to do in a programming language?
For example in java would I be able to connect to a website, and execute it’s javascript somehow in my program?
Example:
Javascript in website:
function setStatus(a) {
if (a == 1) status1 = true;
else if (a == 2) status2 = true;
else if (a == 3) status3 = true
}
Java program:
URL site = new URL("http://somesite.com/page.html");
URLConnection siteConnect = site.openConnection();
siteConnect.connect();
Would I be able to execute setStatus(1) setStatus(2) setStatus(3) inside the java program? How could it be done?
You’re looking for an environment that includes both a Javascript engine and the browser DOM and JS builtins; therefore your easiest bet is going to be something like a browser.
First stop for you should probably be HTMLUnit , which has Javascript support via Rhino and provides all the browser-specific JS objects. That may be everything you need.
If you want to go deeper, you could hook into a full browser engine by developing against Webkit. Two ports to look at are QtWebkit (if speed is not a criteria for you) or Google’s Chromium. Beware that setting either of those up will be a time investment.