views:

26

answers:

2

This post is similar to this post, but not exactly, so I'm asking this question.

How does one go about, From a Java WebStart app:

  • launch a new browser window with a target URL?

  • bring an existing browser window into focus with a target URL?

Is the solution OS/platform independent? Does it matter which browser you're talking to?

A: 

launch a new browser window with a target URL

Use the BasicService's showDocument method.

import javax.jnlp.*;

// Other stuff here

   try {
       // Lookup the javax.jnlp.BasicService object
       BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
       // Invoke the showDocument method
       bs.showDocument(url); // returns a boolean
   } catch(UnavailableServiceException ue) {
       // Service is not supported
   } 

bring an existing browser window into focus with a target URL?

That, unfortunately, I don't know.

R. Bemrose
My reading of the `showDocument` javadoc is that it *might* open a new browser window, or it *might* load the document into an existing browser window.
Stephen C
A: 

See @R. Bemrose answer, with the caveat that it is not clear whether showDocument will or will not always open a new browser window.

Is the solution OS/platform independent? Does it matter which browser you're talking to?

The solution is notionally OS/platform/browser independent, but the behavior may be OS/platform/browser specific. As you should expect. We are talking about interactions with components that are not implemented by Sun and that don't conform to any relevant API standards.

Another issue is that your code may want to open a new browser window, or load into an existing one, but the ultimate decision should rest with the user via his/her browser preferences. We are talking about (potentially) unwanted popups here ... the kind of things that many users find intensely annoying.

Stephen C
Very good point regarding the popups. Using the two platforms is a constraint/requirement that has already been decided. Window management will be a BIG issue. If possible, windows will close the others for appropriate content transitions to make the user experience more seamless.
milesmeow