public final class WebEngine
extends java.lang.Object
WebEngine
is a non-visual object capable of managing one Web page
at a time. It loads Web pages, creates their document models, applies
styles as necessary, and runs JavaScript on pages. It provides access
to the document model of the current page, and enables two-way
communication between a Java application and JavaScript code of the page.
Loading Web Pages
The WebEngine
class provides two ways to load content into a
WebEngine
object:
load(java.lang.String)
method. This method uses
the java.net
package for network access and protocol handling.
loadContent(java.lang.String, java.lang.String)
and
loadContent(java.lang.String)
methods.
Loading always happens on a background thread. Methods that initiate
loading return immediately after scheduling a background job. To track
progress and/or cancel a job, use the javafx.concurrent.Worker
instance available from the getLoadWorker()
method.
The following example changes the stage title when loading completes successfully:
import javafx.concurrent.Worker.State;
final Stage stage;
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
stage.setTitle(webEngine.getLocation());
}
}
});
webEngine.load("http://javafx.com");
User Interface Callbacks
A number of user interface callbacks may be registered with a
WebEngine
object. These callbacks are invoked when a script running
on the page requests a user interface operation to be performed, for
example, opens a popup window or changes status text. A WebEngine
object cannot handle such requests internally, so it passes the request to
the corresponding callbacks. If no callback is defined for a specific
operation, the request is silently ignored.
The table below shows JavaScript user interface methods and properties
with their corresponding WebEngine
callbacks:
JavaScript method/property | WebEngine callback |
---|---|
window.alert() | onAlert |
window.confirm() | confirmHandler |
window.open() | createPopupHandler |
window.open() andwindow.close() | onVisibilityChanged |
window.prompt() | promptHandler |
Setting window.status | onStatusChanged |
Setting any of the following:window.innerWidth , window.innerHeight ,window.outerWidth , window.outerHeight ,window.screenX , window.screenY ,window.screenLeft , window.screenTop |
onResized |
The following example shows a callback that resizes a browser window:
Stage stage;
webEngine.setOnResized(
new EventHandler<WebEvent<Rectangle2D>>() {
public void handle(WebEvent<Rectangle2D> ev) {
Rectangle2D r = ev.getData();
stage.setWidth(r.getWidth());
stage.setHeight(r.getHeight());
}
});
Access to Document Model
The WebEngine
objects create and manage a Document Object Model
(DOM) for their Web pages. The model can be accessed and modified using
Java DOM Core classes. The getDocument()
method provides access
to the root of the model. Additionally DOM Event specification is supported
to define event handlers in Java code.
The following example attaches a Java event listener to an element of a Web page. Clicking on the element causes the application to exit:
EventListener listener = new EventListener() {
public void handleEvent(Event ev) {
Platform.exit();
}
};
Document doc = webEngine.getDocument();
Element el = doc.getElementById("exit-app");
((EventTarget) el).addEventListener("click", listener, false);
Evaluating JavaScript expressions
It is possible to execute arbitrary JavaScript code in the context of
the current page using the executeScript(java.lang.String)
method. For example:
webEngine.executeScript("history.back()");
The execution result is returned to the caller, as described in the next section.
Mapping JavaScript values to Java objects
JavaScript values are represented using the obvious Java classes: null becomes Java null; a boolean becomes ajava.lang.Boolean
;
and a string becomes a java.lang.String
.
A number can be java.lang.Double
or a java.lang.Integer
,
depending.
The undefined value maps to a specific unique String
object whose value is "undefined"
.
If the result is a
JavaScript object, it is wrapped as an instance of the
netscape.javascript.JSObject
class.
(As a special case, if the JavaScript object is
a JavaRuntimeObject
as discussed in the next section,
then the original Java object is extracted instead.)
The JSObject
class is a proxy that provides access to
methods and properties of its underlying JavaScript object.
The most commonly used JSObject
methods are
getMember
(to read a named property),
setMember
(to set or define a property),
and call
(to call a function-valued property).
A DOM Node
is mapped to an object that both extends
JSObject
and implements the appropriate DOM interfaces.
To get a JSObject
object for a Node
just do a cast:
JSObject jdoc = (JSObject) webEngine.getDocument();
In some cases the context provides a specific Java type that guides
the conversion.
For example if setting a Java String
field from a JavaScript
expression, then the JavaScript value is converted to a string.
Mapping Java objects to JavaScript values
The arguments of theJSObject
methods setMember
and
call
pass Java objects to the JavaScript environment.
This is roughly the inverse of the JavaScript-to-Java mapping
described above:
Java String
, Number
, or Boolean
objects
are converted to the obvious JavaScript values. A JSObject
object is converted to the original wrapped JavaScript object.
Otherwise a JavaRuntimeObject
is created. This is
a JavaScript object that acts as a proxy for the Java object,
in that accessing properties of the JavaRuntimeObject
causes the Java field or method with the same name to be accessed.
Note that the Java objects bound using
JSObject.setMember
,
JSObject.setSlot
, and
JSObject.call
are implemented using weak references. This means that the Java object
can be garbage collected, causing subsequent accesses to the JavaScript
objects to have no effect.
Calling back to Java from JavaScript
The JSObject.setMember
method is useful to enable upcalls from JavaScript
into Java code, as illustrated by the following example. The Java code
establishes a new JavaScript object named app
. This object has one
public member, the method exit
.
public class JavaApplication {
public void exit() {
Platform.exit();
}
}
...
JavaApplication javaApp = new JavaApplication();
JSObject window = (JSObject) webEngine.executeScript("window");
window.setMember("app", javaApp);
You can then refer to the object and the method from your HTML page:
<a href="" onclick="app.exit()">Click here to exit application</a>
When a user clicks the link the application is closed.
Note that in the above example, the application holds a reference
to the JavaApplication
instance. This is required for the callback
from JavaScript to execute the desired method.
In the following example, the application does not hold a reference to the Java object:
JSObject window = (JSObject) webEngine.executeScript("window");
window.setMember("app", new JavaApplication());
In this case, since the property value is a local object, "new JavaApplication()"
,
the value may be garbage collected in next GC cycle.
When a user clicks the link, it does not guarantee to execute the callback method exit
.
If there are multiple Java methods with the given name, then the engine selects one matching the number of parameters in the call. (Varargs are not handled.) An unspecified one is chosen if there are multiple ones with the correct number of parameters.
You can pick a specific overloaded method by listing the
parameter types in an "extended method name", which has the
form "method_name(param_type1,...,param_typen)"
. Typically you'd write the JavaScript expression:
receiver["method_name(param_type1,...,param_typeN)"](arg1,...,argN)
The Java class and method must both be declared public.
Deploying an Application as a Module
If any Java class passed to JavaScript is in a named module, then it must
be reflectively accessible to the javafx.web
module.
A class is reflectively accessible if the module
opens
the containing package to at
least the javafx.web
module.
Otherwise, the method will not be called, and no error or
warning will be produced.
For example, if com.foo.MyClass
is in the foo.app
module,
the module-info.java
might
look like this:
module foo.app {
opens com.foo to javafx.web;
}
Alternatively, a class is reflectively accessible if the module
exports
the containing package
unconditionally.
Threading
WebEngine
objects must be created and accessed solely from the
JavaFX Application thread. This rule also applies to any DOM and JavaScript
objects obtained from the WebEngine
object.
Type | Property and Description |
---|---|
<any> |
confirmHandler
JavaScript
confirm handler property. |
<any> |
createPopupHandler
JavaScript popup handler property.
|
<any> |
document
Document object for the current Web page.
|
BooleanProperty |
javaScriptEnabled
Specifies whether JavaScript execution is enabled.
|
ReadOnlyStringProperty |
location
URL of the current Web page.
|
<any> |
onAlert
JavaScript
alert handler property. |
<any> |
onError
The event handler called when an error occurs.
|
<any> |
onResized
JavaScript window resize handler property.
|
<any> |
onStatusChanged
JavaScript status handler property.
|
<any> |
onVisibilityChanged
JavaScript window visibility handler property.
|
<any> |
promptHandler
JavaScript
prompt handler property. |
ReadOnlyStringProperty |
title
Title of the current Web page.
|
StringProperty |
userAgent
Specifies user agent ID string.
|
<any> |
userDataDirectory
Specifies the directory to be used by this
WebEngine
to store local user data. |
StringProperty |
userStyleSheetLocation
Location of the user stylesheet as a string URL.
|
Modifier and Type | Class and Description |
---|---|
private static class |
WebEngine.AccessorImpl |
private class |
WebEngine.DebuggerImpl
The debugger implementation.
|
private class |
WebEngine.DocumentProperty |
private static class |
WebEngine.InspectorClientImpl
The inspector client implementation.
|
private class |
WebEngine.LoadWorker |
private static class |
WebEngine.PageLoadListener
The page load event listener.
|
private static class |
WebEngine.PulseTimer
Drives the
Timer when Timer.Mode.PLATFORM_TICKS is set. |
private static class |
WebEngine.SelfDisposer |
Modifier and Type | Field and Description |
---|---|
private <any> |
confirmHandler |
private <any> |
createPopupHandler |
private WebEngine.DebuggerImpl |
debugger |
private WebEngine.SelfDisposer |
disposer |
private WebEngine.DocumentProperty |
document |
private WebHistory |
history |
private static int |
instanceCount
The number of instances of this class.
|
private BooleanProperty |
javaScriptEnabled
Specifies whether JavaScript execution is enabled.
|
private WebEngine.LoadWorker |
loadWorker
The Worker which shows progress of the web engine as it loads pages.
|
private ReadOnlyStringWrapper |
location |
private static PlatformLogger |
logger |
private <any> |
onAlert |
private <any> |
onError
The event handler called when an error occurs.
|
private <any> |
onResized |
private <any> |
onStatusChanged |
private <any> |
onVisibilityChanged |
private WebPage |
page
The object that provides interaction with the native webkit core.
|
private <any> |
promptHandler |
private ReadOnlyStringWrapper |
title |
private StringProperty |
userAgent
Specifies user agent ID string.
|
private <any> |
userDataDirectory
Specifies the directory to be used by this
WebEngine
to store local user data. |
private boolean |
userDataDirectoryApplied |
private StringProperty |
userStyleSheetLocation
Location of the user stylesheet as a string URL.
|
private <any> |
view
The node associated with this engine.
|
Modifier | Constructor and Description |
---|---|
|
WebEngine()
Creates a new engine.
|
|
WebEngine(java.lang.String url)
Creates a new engine and loads a Web page into it.
|
private |
WebEngine(java.lang.String url,
boolean callLoad) |
Modifier and Type | Method and Description |
---|---|
private void |
applyUserDataDirectory() |
(package private) static void |
checkThread() |
<any> |
confirmHandlerProperty()
JavaScript
confirm handler property. |
private static void |
createDirectories(java.io.File directory) |
<any> |
createPopupHandlerProperty()
JavaScript popup handler property.
|
private static java.io.File |
defaultUserDataDirectory() |
(package private) void |
dispose() |
<any> |
documentProperty()
Document object for the current Web page.
|
java.lang.Object |
executeScript(java.lang.String script)
Executes a script in the context of the current page.
|
private void |
fireError(<any> eventType,
java.lang.String message,
java.lang.Throwable exception) |
<any> |
getConfirmHandler()
Gets the value of the property confirmHandler.
|
<any> |
getCreatePopupHandler()
Gets the value of the property createPopupHandler.
|
(package private) Debugger |
getDebugger() |
org.w3c.dom.Document |
getDocument()
Gets the value of the property document.
|
WebHistory |
getHistory()
Returns the session history object.
|
<any> |
getLoadWorker()
Returns a
javafx.concurrent.Worker object that can be used to
track loading progress. |
java.lang.String |
getLocation()
Gets the value of the property location.
|
private long |
getMainFrame() |
<any> |
getOnAlert()
Gets the value of the property onAlert.
|
<any> |
getOnError()
Gets the value of the property onError.
|
<any> |
getOnResized()
Gets the value of the property onResized.
|
<any> |
getOnStatusChanged()
Gets the value of the property onStatusChanged.
|
<any> |
getOnVisibilityChanged()
Gets the value of the property onVisibilityChanged.
|
(package private) WebPage |
getPage() |
<any> |
getPromptHandler()
Gets the value of the property promptHandler.
|
java.lang.String |
getTitle()
Gets the value of the property title.
|
java.lang.String |
getUserAgent()
Gets the value of the property userAgent.
|
java.io.File |
getUserDataDirectory()
Gets the value of the property userDataDirectory.
|
java.lang.String |
getUserStyleSheetLocation()
Gets the value of the property userStyleSheetLocation.
|
boolean |
isJavaScriptEnabled()
Gets the value of the property javaScriptEnabled.
|
BooleanProperty |
javaScriptEnabledProperty()
Specifies whether JavaScript execution is enabled.
|
void |
load(java.lang.String url)
Loads a Web page into this engine.
|
void |
loadContent(java.lang.String content)
Loads the given HTML content directly.
|
void |
loadContent(java.lang.String content,
java.lang.String contentType)
Loads the given content directly.
|
ReadOnlyStringProperty |
locationProperty()
URL of the current Web page.
|
<any> |
onAlertProperty()
JavaScript
alert handler property. |
<any> |
onErrorProperty()
The event handler called when an error occurs.
|
<any> |
onResizedProperty()
JavaScript window resize handler property.
|
<any> |
onStatusChangedProperty()
JavaScript status handler property.
|
<any> |
onVisibilityChangedProperty()
JavaScript window visibility handler property.
|
void |
print(PrinterJob job)
Prints the current Web page using the given printer job.
|
private static boolean |
printStatusOK(PrinterJob job) |
<any> |
promptHandlerProperty()
JavaScript
prompt handler property. |
private byte[] |
readFully(java.io.BufferedInputStream in) |
void |
reload()
Reloads the current page, whether loaded from URL or directly from a String in
one of the
loadContent methods. |
void |
setConfirmHandler(<any> handler)
Sets the value of the property confirmHandler.
|
void |
setCreatePopupHandler(<any> handler)
Sets the value of the property createPopupHandler.
|
void |
setJavaScriptEnabled(boolean value)
Sets the value of the property javaScriptEnabled.
|
void |
setOnAlert(<any> handler)
Sets the value of the property onAlert.
|
void |
setOnError(<any> handler)
Sets the value of the property onError.
|
void |
setOnResized(<any> handler)
Sets the value of the property onResized.
|
void |
setOnStatusChanged(<any> handler)
Sets the value of the property onStatusChanged.
|
void |
setOnVisibilityChanged(<any> handler)
Sets the value of the property onVisibilityChanged.
|
void |
setPromptHandler(<any> handler)
Sets the value of the property promptHandler.
|
void |
setUserAgent(java.lang.String value)
Sets the value of the property userAgent.
|
void |
setUserDataDirectory(java.io.File value)
Sets the value of the property userDataDirectory.
|
void |
setUserStyleSheetLocation(java.lang.String value)
Sets the value of the property userStyleSheetLocation.
|
(package private) void |
setView(WebView view) |
private void |
stop() |
ReadOnlyStringProperty |
titleProperty()
Title of the current Web page.
|
private void |
updateLocation(java.lang.String value) |
private void |
updateTitle() |
StringProperty |
userAgentProperty()
Specifies user agent ID string.
|
<any> |
userDataDirectoryProperty()
Specifies the directory to be used by this
WebEngine
to store local user data. |
StringProperty |
userStyleSheetLocationProperty()
Location of the user stylesheet as a string URL.
|
public final <any> documentProperty
null
if the Web page failed to load.getDocument()
public final ReadOnlyStringProperty locationProperty
getLocation()
public final ReadOnlyStringProperty titleProperty
null
.getTitle()
public final BooleanProperty javaScriptEnabledProperty
isJavaScriptEnabled()
,
setJavaScriptEnabled(boolean)
public final StringProperty userStyleSheetLocationProperty
This should be a local URL, i.e. either 'data:'
,
'file:'
, or 'jar:'
. Remote URLs are not allowed
for security reasons.
getUserStyleSheetLocation()
,
setUserStyleSheetLocation(String)
public final <any> userDataDirectoryProperty
WebEngine
to store local user data.
If the value of this property is not null
,
the WebEngine
will attempt to store local user data
in the respective directory.
If the value of this property is null
,
the WebEngine
will attempt to store local user data
in an automatically selected system-dependent user- and
application-specific directory.
When a WebEngine
is about to start loading a web
page or executing a script for the first time, it checks whether
it can actually use the directory specified by this property.
If the check fails for some reason, the WebEngine
invokes
the WebEngine.onError
event handler,
if any, with a WebErrorEvent
describing the reason.
If the invoked event handler modifies the userDataDirectory
property, the WebEngine
retries with the new value as soon
as the handler returns. If the handler does not modify the
userDataDirectory
property (which is the default),
the WebEngine
continues without local user data.
Once the WebEngine
has started loading a web page or
executing a script, changes made to this property have no effect
on where the WebEngine
stores or will store local user
data.
Currently, the directory specified by this property is used
only to store the data that backs the window.localStorage
objects. In the future, more types of data can be added.
getUserDataDirectory()
,
setUserDataDirectory(File)
public final StringProperty userAgentProperty
User-Agent
HTTP header.getUserAgent()
,
setUserAgent(String)
public final <any> onAlertProperty
alert
handler property. This handler is invoked
when a script running on the Web page calls the alert
function.getOnAlert()
,
#setOnAlert()
public final <any> onStatusChangedProperty
window.status
property.getOnStatusChanged()
,
#setOnStatusChanged()
public final <any> onResizedProperty
window
object.getOnResized()
,
#setOnResized()
public final <any> onVisibilityChangedProperty
window
object.getOnVisibilityChanged()
,
#setOnVisibilityChanged()
public final <any> createPopupHandlerProperty
To satisfy this request a handler may create a new WebEngine
,
attach a visibility handler and optionally a resize handler, and return
the newly created engine. To block the popup, a handler should return
null
.
By default, a popup handler is installed that opens popups in this
WebEngine
.
getCreatePopupHandler()
,
#setCreatePopupHandler()
public final <any> confirmHandlerProperty
confirm
handler property. This handler is invoked
when a script running on the Web page calls the confirm
function.
An implementation may display a dialog box with Yes and No options, and return the user's choice.
getConfirmHandler()
,
#setConfirmHandler()
public final <any> promptHandlerProperty
prompt
handler property. This handler is invoked
when a script running on the Web page calls the prompt
function.
An implementation may display a dialog box with an text field, and return the user's input.
getPromptHandler()
,
#setPromptHandler()
public final <any> onErrorProperty
getOnError()
,
#setOnError()
private static final PlatformLogger logger
private static int instanceCount
private final <any> view
private final WebEngine.LoadWorker loadWorker
private final WebPage page
private final WebEngine.SelfDisposer disposer
private final WebEngine.DebuggerImpl debugger
private boolean userDataDirectoryApplied
private final WebEngine.DocumentProperty document
private final ReadOnlyStringWrapper location
private final ReadOnlyStringWrapper title
private BooleanProperty javaScriptEnabled
private StringProperty userStyleSheetLocation
This should be a local URL, i.e. either 'data:'
,
'file:'
, or 'jar:'
. Remote URLs are not allowed
for security reasons.
private final <any> userDataDirectory
WebEngine
to store local user data.
If the value of this property is not null
,
the WebEngine
will attempt to store local user data
in the respective directory.
If the value of this property is null
,
the WebEngine
will attempt to store local user data
in an automatically selected system-dependent user- and
application-specific directory.
When a WebEngine
is about to start loading a web
page or executing a script for the first time, it checks whether
it can actually use the directory specified by this property.
If the check fails for some reason, the WebEngine
invokes
the WebEngine.onError
event handler,
if any, with a WebErrorEvent
describing the reason.
If the invoked event handler modifies the userDataDirectory
property, the WebEngine
retries with the new value as soon
as the handler returns. If the handler does not modify the
userDataDirectory
property (which is the default),
the WebEngine
continues without local user data.
Once the WebEngine
has started loading a web page or
executing a script, changes made to this property have no effect
on where the WebEngine
stores or will store local user
data.
Currently, the directory specified by this property is used
only to store the data that backs the window.localStorage
objects. In the future, more types of data can be added.
private StringProperty userAgent
User-Agent
HTTP header.private final <any> onAlert
private final <any> onStatusChanged
private final <any> onResized
private final <any> onVisibilityChanged
private final <any> createPopupHandler
private final <any> confirmHandler
private final <any> promptHandler
private final <any> onError
private final WebHistory history
public WebEngine()
public WebEngine(java.lang.String url)
url
- the URL of the web page to loadprivate WebEngine(java.lang.String url, boolean callLoad)
public final <any> getLoadWorker()
javafx.concurrent.Worker
object that can be used to
track loading progress.Worker
objectpublic final org.w3c.dom.Document getDocument()
public final <any> documentProperty()
null
if the Web page failed to load.getDocument()
public final java.lang.String getLocation()
public final ReadOnlyStringProperty locationProperty()
getLocation()
private void updateLocation(java.lang.String value)
public final java.lang.String getTitle()
public final ReadOnlyStringProperty titleProperty()
null
.getTitle()
private void updateTitle()
public final void setJavaScriptEnabled(boolean value)
public final boolean isJavaScriptEnabled()
public final BooleanProperty javaScriptEnabledProperty()
isJavaScriptEnabled()
,
setJavaScriptEnabled(boolean)
public final void setUserStyleSheetLocation(java.lang.String value)
public final java.lang.String getUserStyleSheetLocation()
private byte[] readFully(java.io.BufferedInputStream in) throws java.io.IOException
java.io.IOException
public final StringProperty userStyleSheetLocationProperty()
This should be a local URL, i.e. either 'data:'
,
'file:'
, or 'jar:'
. Remote URLs are not allowed
for security reasons.
getUserStyleSheetLocation()
,
setUserStyleSheetLocation(String)
public final java.io.File getUserDataDirectory()
public final void setUserDataDirectory(java.io.File value)
public final <any> userDataDirectoryProperty()
WebEngine
to store local user data.
If the value of this property is not null
,
the WebEngine
will attempt to store local user data
in the respective directory.
If the value of this property is null
,
the WebEngine
will attempt to store local user data
in an automatically selected system-dependent user- and
application-specific directory.
When a WebEngine
is about to start loading a web
page or executing a script for the first time, it checks whether
it can actually use the directory specified by this property.
If the check fails for some reason, the WebEngine
invokes
the WebEngine.onError
event handler,
if any, with a WebErrorEvent
describing the reason.
If the invoked event handler modifies the userDataDirectory
property, the WebEngine
retries with the new value as soon
as the handler returns. If the handler does not modify the
userDataDirectory
property (which is the default),
the WebEngine
continues without local user data.
Once the WebEngine
has started loading a web page or
executing a script, changes made to this property have no effect
on where the WebEngine
stores or will store local user
data.
Currently, the directory specified by this property is used
only to store the data that backs the window.localStorage
objects. In the future, more types of data can be added.
getUserDataDirectory()
,
setUserDataDirectory(File)
public final void setUserAgent(java.lang.String value)
public final java.lang.String getUserAgent()
public final StringProperty userAgentProperty()
User-Agent
HTTP header.getUserAgent()
,
setUserAgent(String)
public final <any> getOnAlert()
public final void setOnAlert(<any> handler)
public final <any> onAlertProperty()
alert
handler property. This handler is invoked
when a script running on the Web page calls the alert
function.getOnAlert()
,
#setOnAlert()
public final <any> getOnStatusChanged()
public final void setOnStatusChanged(<any> handler)
public final <any> onStatusChangedProperty()
window.status
property.getOnStatusChanged()
,
#setOnStatusChanged()
public final <any> getOnResized()
public final void setOnResized(<any> handler)
public final <any> onResizedProperty()
window
object.getOnResized()
,
#setOnResized()
public final <any> getOnVisibilityChanged()
public final void setOnVisibilityChanged(<any> handler)
public final <any> onVisibilityChangedProperty()
window
object.getOnVisibilityChanged()
,
#setOnVisibilityChanged()
public final <any> getCreatePopupHandler()
public final void setCreatePopupHandler(<any> handler)
public final <any> createPopupHandlerProperty()
To satisfy this request a handler may create a new WebEngine
,
attach a visibility handler and optionally a resize handler, and return
the newly created engine. To block the popup, a handler should return
null
.
By default, a popup handler is installed that opens popups in this
WebEngine
.
getCreatePopupHandler()
,
#setCreatePopupHandler()
public final <any> getConfirmHandler()
public final void setConfirmHandler(<any> handler)
public final <any> confirmHandlerProperty()
confirm
handler property. This handler is invoked
when a script running on the Web page calls the confirm
function.
An implementation may display a dialog box with Yes and No options, and return the user's choice.
getConfirmHandler()
,
#setConfirmHandler()
public final <any> getPromptHandler()
public final void setPromptHandler(<any> handler)
public final <any> promptHandlerProperty()
prompt
handler property. This handler is invoked
when a script running on the Web page calls the prompt
function.
An implementation may display a dialog box with an text field, and return the user's input.
getPromptHandler()
,
#setPromptHandler()
public final <any> getOnError()
public final void setOnError(<any> handler)
public final <any> onErrorProperty()
getOnError()
,
#setOnError()
public void load(java.lang.String url)
url
- URL of the web page to loadpublic void loadContent(java.lang.String content)
load(String)
, this method is asynchronous.content
- the HTML content to loadpublic void loadContent(java.lang.String content, java.lang.String contentType)
load(String)
, this method is asynchronous. This method also allows you to
specify the content type of the string being loaded, and so may optionally support
other types besides just HTML.content
- the HTML content to loadcontentType
- the type of content to loadpublic void reload()
loadContent
methods.public WebHistory getHistory()
public java.lang.Object executeScript(java.lang.String script)
script
- the scriptjava.lang.Integer
java.lang.Double
java.lang.String
java.lang.Boolean
null
to null
netscape.javascript.JSObject
netscape.javascript.JSObject
, that also implement
org.w3c.dom.Node
JavaRuntimeObject
which is used to wrap a Java object as a JavaScript value - in this
case we just extract the original Java value.
private long getMainFrame()
WebPage getPage()
void setView(WebView view)
private void stop()
private void applyUserDataDirectory()
private static java.io.File defaultUserDataDirectory()
private static void createDirectories(java.io.File directory) throws java.io.IOException
java.io.IOException
private void fireError(<any> eventType, java.lang.String message, java.lang.Throwable exception)
void dispose()
static void checkThread()
Debugger getDebugger()
private static final boolean printStatusOK(PrinterJob job)
public void print(PrinterJob job)
This method does not modify the state of the job, nor does it call
PrinterJob#endJob
, so the job may be safely reused afterwards.
job
- printer job used for printing