Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/WebKit.framework |
Availability | Available in Mac OS X v10.3.9 and later. |
Companion guide | |
Declared in | WebScriptObject.h |
Related sample code |
A WebScriptObject
object is an Objective-C wrapper for a scripting object passed to your application from the scripting environment.
You can not create a WebScriptObject
object directly. You get a window WebScriptObject
object by sending windowScriptObject
to your WebView
object.
You can use key-value coding methods—for example, setValue:forKey:
and valueForKey:
—to get and set properties of a WebScriptObject
object. You can also access properties by index using the setWebScriptValueAtIndex:value:
and webScriptValueAtIndex:
methods. Use the removeWebScriptKey:
method to remove a scripting object property.
Not all properties and methods of a class are exported. Use the setValue:forUndefinedKey:
and valueForUndefinedKey:
methods to intercept access to properties that are not exported. Similarly, use the invokeUndefinedMethodFromWebScript:withArguments:
method to intercept method invocations that are not exported.
If you want access to properties and methods defined in your own classes, use the methods in the WebScripting
informal protocol to specify the properties and methods the class should export to WebKit’s JavaScript environment.
Use the callWebScriptMethod:withArguments:
and evaluateWebScript:
methods to execute scripts in the scripting environment.
Raises an exception in the current script execution context.
+ (BOOL)throwException:(NSString *)exceptionMessage
The exception message.
YES
if successful, NO
otherwise.
WebScriptObject.h
Returns the result of executing a method in the scripting environment.
- (id)callWebScriptMethod:(NSString *)namewithArguments:(NSArray *)args
The name of the method to invoke.
The values to pass to the method.
The return value of the method. Returns WebUndefined
if an exception is thrown in the JavaScript environment or the method has no return value.
WebScriptObject.h
Returns the result of evaluating a script in the scripting environment.
- (id)evaluateWebScript:(NSString *)script
The script to evaluate.
The scripting object. The format of the script is dependent on the target scripting environment. Returns WebUndefined
if an exception is thrown in the JavaScript environment or there is no return value.
WebScriptObject.h
Returns the JavaScript object corresponding to the receiver.
- (JSObjectRef)JSObject
The JavaScript object corresponding to the receiver in the JavaScriptCore C API.
WebScriptObject.h
Removes a property from a scripting environment.
- (void)removeWebScriptKey:(NSString *)name
Property to remove.
WebScriptObject.h
Raises a scripting environment exception in the context of the current object.
- (void)setException:(NSString *)description
Description of the exception.
WebScriptObject.h
Sets the value of a property at the specified index.
- (void)setWebScriptValueAtIndex:(unsigned)indexvalue:(id)value
The index of the property.
The value of the property.
WebScriptObject.h
Returns a string representation of the receiver.
- (NSString *)stringRepresentation
The string representation of the receiver.
The coercion of nonstring objects is dependent on the scripting environment.
WebScriptObject.h
Returns the value of a property at the specified index.
- (id)webScriptValueAtIndex:(unsigned)index
The index of the property.
The value of a property at index. Returns WebUndefined
if an exception is thrown in the JavaScript environment.
Accessing property values by index is dependent on the scripting environment.
WebScriptObject.h
© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-04-08)