简体   繁体   中英

Java Webstart…interaction with browsers on different platforms

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM