Class HostServices
- javafx.application.HostServices
public final class HostServices extends Object
Since:
JavaFX 2.0
-
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description StringgetCodeBase()Gets the code base URI for this application.StringgetDocumentBase()Gets the document base URI for this application.JSObjectgetWebContext()Returns the JavaScript handle of the enclosing DOM window of the web page containing this application.StringresolveURI(String base, String rel)Resolves the specified relative URI against the base URI and returns the resolved URI.voidshowDocument(String uri)Opens the specified URI in a new browser window or tab.
-
Method Detail
-
getCodeBase
public final String getCodeBase()
Gets the code base URI for this application. If the application was launched via a JNLP file, this method returns the codebase parameter specified in the JNLP file. If the application was launched in standalone mode, this method returns the directory containing the application jar file. If the application is not packaged in a jar file, this method returns the empty string.Returns:
the code base URI for this application.
-
getDocumentBase
public final String getDocumentBase()
Gets the document base URI for this application. If the application is embedded in a browser, this method returns the URI of the web page containing the application. If the application was launched in webstart mode, this method returns the the codebase parameter specified in the JNLP file (the document base and the code base are the same in this mode). If the application was launched in standalone mode, this method returns the URI of the current directory.Returns:
the document base URI for this application.
-
resolveURI
public final String resolveURI(String base, String rel)Resolves the specified relative URI against the base URI and returns the resolved URI.Example:
HostServices services = getHostServices(); String myImage = services.resolveURI(services.getDocumentBase(), "image.jpg"); Image image = new Image(myImage);Parameters:
base- the base URI against which to resolve the relative URIReturns:
the fully resolved URI.
Throws:
NullPointerException- if either thebaseor therelstrings are null.
-
showDocument
public final void showDocument(String uri)
Opens the specified URI in a new browser window or tab. The determination of whether it is a new browser window or a tab in an existing browser window will be made by the browser preferences. Note that this will respect the pop-up blocker settings of the default browser; it will not try to circumvent them.Parameters:
uri- the URI of the web page that will be opened in a browser.
-
getWebContext
public final JSObject getWebContext()
Returns the JavaScript handle of the enclosing DOM window of the web page containing this application. This handle is used to access the web page by calling from Java into JavaScript. If the application is not embedded into a web page, this method return null.Example:
JSObject jsWin = getHostServices().getWebContext(); if (jsWin != null) { jsWin.eval("var b = document.body;" + "var newdiv = document.createElement('div');" + "newdiv.innerHTML = '<br>Hello from JavaScript!';" + "b.appendChild(newdiv);"); }Returns:
handle of the enclosing DOM window of the web page containing this application
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.