public abstract class JSObject extends Object
Allows Java code to manipulate JavaScript objects.
When a JavaScript object is passed or returned to Java code, it
is wrapped in an instance of JSObject
. When a
JSObject
instance is passed to the JavaScript engine,
it is unwrapped back to its original JavaScript object. The
JSObject
class provides a way to invoke JavaScript
methods and examine JavaScript properties.
Any data returned from the JavaScript engine to Java is converted to Java data types. Certain data passed to the JavaScript engine is converted to JavaScript data types. See the section on Data Type Conversions in the new LiveConnect Specification for details on how values are converted.
Modifier | Constructor and Description |
---|---|
protected |
JSObject()
Constructs a new JSObject.
|
Modifier and Type | Method and Description |
---|---|
abstract Object |
call(String methodName,
Object... args)
Calls a JavaScript method.
|
abstract Object |
eval(String s)
Evaluates a JavaScript expression.
|
abstract Object |
getMember(String name)
Retrieves a named member of a JavaScript object.
|
abstract Object |
getSlot(int index)
Retrieves an indexed member of a JavaScript object.
|
static JSObject |
getWindow(Applet applet)
Returns a JSObject for the window containing the given applet.
|
abstract void |
removeMember(String name)
Removes a named member of a JavaScript object.
|
abstract void |
setMember(String name,
Object value)
Sets a named member of a JavaScript object.
|
abstract void |
setSlot(int index,
Object value)
Sets an indexed member of a JavaScript object.
|
protected JSObject()
public abstract Object call(String methodName, Object... args) throws JSException
Calls a JavaScript method. Equivalent to "this.methodName(args[0], args[1], ...)" in JavaScript.
methodName
- The name of the JavaScript method to be invoked.args
- the Java objects passed as arguments to the method.JSException
public abstract Object eval(String s) throws JSException
Evaluates a JavaScript expression. The expression is a string of JavaScript source code which will be evaluated in the context given by "this".
s
- The JavaScript expression.JSException
public abstract Object getMember(String name) throws JSException
Retrieves a named member of a JavaScript object. Equivalent to "this.name" in JavaScript.
name
- The name of the JavaScript property to be accessed.JSException
public abstract void setMember(String name, Object value) throws JSException
Sets a named member of a JavaScript object. Equivalent to "this.name = value" in JavaScript.
name
- The name of the JavaScript property to be accessed.value
- The value of the propery.JSException
public abstract void removeMember(String name) throws JSException
Removes a named member of a JavaScript object. Equivalent to "delete this.name" in JavaScript.
name
- The name of the JavaScript property to be removed.JSException
public abstract Object getSlot(int index) throws JSException
Retrieves an indexed member of a JavaScript object. Equivalent to "this[index]" in JavaScript.
index
- The index of the array to be accessed.JSException
public abstract void setSlot(int index, Object value) throws JSException
Sets an indexed member of a JavaScript object. Equivalent to "this[index] = value" in JavaScript.
index
- The index of the array to be accessed.JSException
public static JSObject getWindow(Applet applet) throws JSException
Returns a JSObject for the window containing the given applet.
applet
- The applet.JSException
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.