public final class HostServices extends Object
| Modifier and Type | Method and Description |
|---|---|
String |
getCodeBase()
Gets the code base URI for this application.
|
String |
getDocumentBase()
Gets the document base URI for this application.
|
JSObject |
getWebContext()
Returns the JavaScript handle of the enclosing DOM window of the web
page containing this application.
|
String |
resolveURI(String base,
String rel)
Resolves the specified relative URI against the base URI and returns
the resolved URI.
|
void |
showDocument(String uri)
Opens the specified URI in a new browser window or tab.
|
public final String getCodeBase()
public final String getDocumentBase()
public final String resolveURI(String base, String rel)
Example:
HostServices services = getHostServices();
String myImage = services.resolveURI(services.getDocumentBase(),
"image.jpg");
Image image = new Image(myImage);
base - the base URI against which to resolve the relative URIrel - the relative URI to be resolvedNullPointerException - if either the base or the
rel strings are null.IllegalArgumentException - if there is an error parsing either
the base or rel URI strings, or if there is
any other error in resolving the URI.public final void showDocument(String uri)
uri - the URI of the web page that will be opened in a browser.public final JSObject getWebContext()
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);");
}
Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.