5 Replies Latest reply: Dec 20, 2011 6:39 PM by 905716 RSS

    WebEngine Popup Handler for a skype button, not working.

      I need to create a popup handler that targets an external window. How can I do this? The default opens the popup in the same webview, and there is no code in the JavaFx learning trail to provide me a general idea or anything. Any help is greatly appreciated.

      Edited by: Nestroia on Dec 20, 2011 11:46 AM
        • 1. Re: WebEngine Popup Handler
          There are different kinds of Popups, there are popups to do with JavaScript alerts, confirms and prompts, and there are Popups to do with opening a new window.
          For JavaScript alert popups, etc. you can test by pointing your WebEngine here: http://www.w3schools.com/JS/js_popup.asp.
          The rest of this post does not deal with the javascript popups as I don't think that is what you are asking about.

          If you have implemented a tab strategy for your WebEngine then the Popups for new windows can be opened up in a new tab.
          But it looks like you just want to open a new window when you get the popup request (e.g. a JavaScript open.window function) and host a new WebView inside the new window.

          Here is some code for that:
          engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
            @Override public WebEngine call(PopupFeatures popupFeatures) {
              final WebView popupWebView = new WebView();
              final Scene popupScene = new Scene(popupWebView);
              Stage popupStage = new Stage();
              return popupWebView.getEngine();
          You can test the code out by pointing your WebEngine to this url: http://www.w3schools.com/jsref/met_win_open.asp.

          You can use the parameters inside the PopupFeatures (isResizable, hasMenu, hasStatus and hasToolbar), to customize the look and operation of your new stage. If you are implementing a fairly full featured browser, you can query the has parameters to work out what features to attach to the popped up WebView in the popped up stage. But if you don't require or want any of those other features, you can ignore the PopupFeatures values. Note that the PopupFeatures aren't currently fully featured as JavaScript can pass size parameters to the window and other parameters in the open request which are not propagated through to PopupFeatures, so you won't be able to dynamically size your new popped-up window unless you do something clever. I'll add this to the list of Jira's I should file, but have not yet.

          Note that the above code does not allow for recursive popups, e.g. there is no popup handler in the new popup window - if you wanted to support that, you would need to add a popupHandler to popupWebView.getEngine().
          • 2. Re: WebEngine Popup Handler
            Thanks so much but I tried the code out and it doesn't work for one of the widgets (Skype Button), the popup opens in the original window still.

            It also wont open skype and connect for a phone call. Although it does open skype and connects for a phone call if I open the widget inside a browser. Therefore it is an issue with the JavaFx 2.0 web app.

            Edited by: Nestroia on Dec 20, 2011 11:38 AM
            • 3. Re: WebEngine Popup Handler
              I haven't used Skype much, but last time I did it was by installing software on my PC. The software installed browser plugins in IE and Firefox which were accessible by toolbar buttons or menu items installed with those plugins. Perhaps your issue is that the button you are using is relying on an installed browser plugin. WebView does not support browser plugin installation. It also does not, by default, open native applications such as Skype for phone calls. You could perhaps write some code which uses the Java process API to launch Skype given some kind of trigger, but that would not be native to anything WebView or Skype provide - you would need to implement that trigger and write that code.
              • 4. Re: WebEngine Popup Handler
                I did some investigation to try to work out what a skype button was and found this link http://www.skype.com/intl/en-us/tell-a-friend/get-a-skype-button/, which I guess is similar to what you are trying to use.

                Looking at the code at that link generated for insertion in a web page, it calls out to http://download.skype.com/share/skypebuttons/js/skypeCheck.js which relies on the adobe flash player, which is not supported by JavaFX.

                Furthermore, it tries to launch skype using a custom protocol, which skype installed into the browser and/or OS when the skype native application was installed:
                ...a href="skype:skypeid?call">...skype button html...</a>...
                and there is no way WebView is going to know about that custom protocol unless you wrote your own skype protocol handler and installed it into the JVM.
                • 5. Re: WebEngine Popup Handler for a skype button, not working.
                  Thank you so much for the insight.