views:

549

answers:

3

I have a Java applet consisting of a wizard-like form with three steps. At the final step, the user can click a "finish" button. I want that button to cause the web browser to navigate to a specific URL.

Question: Is there a way to cause the browser to navigate to a specific URL, in such a way that it will work across all modern browsers? My specific browser requirements are FF3+, IE7+, Safari 3+, and Opera 9+. I am using Java 1.5.

+1  A: 

You could initiate the wizard from within JavaScript and have the applet return the execution flow to the JavaScript caller on clicking the 'Finish' button. Once you are in JavaScript you could then navigate to a new location, either by doing a form post or by doing changing the window.location property.

In the worst case, you could examine the use of LiveConnect, but I would touch it with a 10 foot pole.


Update on LiveConnect

The original LiveConnect seems to be limited by nature to browsers running on Windows, and will probably work only on NN and IE. Some of those bugs have been fixed recently, but browser compatibility will continue to be an issue.

Vineet Reynolds
A: 

If you're using Java 6 and above, see the Desktop API. That'll drive a browser. However I don't know if the applet security model will interfere with this.

Other than that, I've used BrowserLauncher2 with success. Similar caveats apply.

Brian Agnew
+6  A: 

From the applet you can simply get the applet context and call showDocument(url).

This will navigate away from the current page to the specified URL:

getAppletContext().showDocument(url);

Additionally you can pass a target parameter.

To visit a relative URL you can use:

URL url = new URL(getCodeBase().getProtocol(),
                          getCodeBase().getHost(),
                          getCodeBase().getPort(),
                          "/next.html");
getAppletContext().showDocument(url);

These work in every major browser since Java version 1.1.

Pool