0

My question is just as the title indicates.

I have a JavaFX app, and need to open a browser window. After opening it, I want to be able to communicate from the browser back to the app that opened it.

For example, if I opened the default browser window like this:

URI u = new URI(url);
java.awt.Desktop.getDesktop().browse(u);
xil3
  • 16,305
  • 8
  • 63
  • 97
  • 1
    Can you give us the code that you use to spawn the window? – Menelaos May 21 '13 at 18:49
  • I don't have any code yet for spawning the window - just wanted to find out if that was actually possible. This is for a potential project, but if this cannot be done, then I need to think of another way to do it. – xil3 May 21 '13 at 20:05
  • If you can [embed your JavaFX app in a webpage](http://docs.oracle.com/javafx/2/deployment/javafx_javascript.htm) the JavaFX app and the html/javascript page it is embedded in can communicate back and forth. Probably not what you are looking for though . . . – jewelsea May 21 '13 at 20:13
  • Thanks jewelsea - we looked at that option. It's pretty much the last thing we'll do, if nothing else works. – xil3 May 21 '13 at 20:15
  • Why would a internal WebView not work? I think averything else will have a lot of ofverhead. – Christian Kuetbach May 21 '13 at 20:15
  • Because an internal WebView can't run Flash. That's one of the requirements, and the reason why I can't just use a WebView. – xil3 May 21 '13 at 20:18
  • To open a document in a browser from JavaFX, it is preferred to use the `showDocument` method from [javafx.application.HostServices](http://docs.oracle.com/javafx/2/api/javafx/application/HostServices.html#showDocument%28java.lang.String%29) instead of [java.awt.Desktop.getDesktop().browse(u)](http://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html#browse%28java.net.URI%29). – jewelsea May 21 '13 at 22:01

2 Answers2

0

You can communicate back and forth with a WebView component. See http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm

If you are launching a page in the hosts browser, you'll need to develop a server based method to communicate.

Andrew
  • 4,574
  • 26
  • 31
  • Yeah, I know it can communicate with a WebView, but I need to know if it's possible to communicate with an external browser window that it just opened. I'm assuming that based on your answer, there isn't really any way, without having some sort of server to pass the data. – xil3 May 21 '13 at 20:03
0

Three options:

Through Javascript

Using javascript, and the window name you could access any window.

E.g. See: https://stackoverflow.com/a/16525481/1688441

Through Ajax Calls and a Server/Database

As another user answered, communication could be done with an intermediate server.

Third party library

The only other thing I can think of is using a 3rd party library to get the window within Operating System, though not much more I can suggest.

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155