<p>I read that you could call JavaScript code from a Java Applet by calling</p>

<pre><code>JApplet.getAppletContext().showDocument( "javascript:alert('Hello World');" );
</code></pre>

<p>However, when I do this i get the following error:</p>

<pre><code>java.net.MalformedURLException: unknown protocol: javascript
</code></pre>

<p>How do I work around this?</p>

```
```
try {
        this.getAppletContext().showDocument(new URL("javascript:alert('hello world');"));
    }catch(Exception e) {
        e.printStackTrace();
    }
```
```
Works !!
Maybe the browser does not have javascript enabled.. just a guess