How do you programmically execute javascript as if from the browser bar?
<p>For example if you type in the browser bar <code>javascript:alert('hai');</code> it shows a pop up.  Is that possible to do in a programming language?</p>

<p>For example in java would I be able to connect to a website, and execute it's javascript somehow in my program?</p>

<p>Example:</p>

<p>Javascript in website:</p>

<pre><code>function setStatus(a) {
    if (a == 1) status1 = true;
    else if (a == 2) status2 = true;
    else if (a == 3) status3 = true
}
</code></pre>

<p>Java program:</p>

<pre><code>URL site = new URL("http://somesite.com/page.html");
URLConnection siteConnect = site.openConnection();
siteConnect.connect();
</code></pre>

<p>Would I be able to execute <code>setStatus(1)</code> <code>setStatus(2)</code> <code>setStatus(3)</code> inside the java program? How could it be done?</p>
