Re: Web scripting key does not work
Christiaan Hofman <[email protected]> Wed, 20 Oct 2010 17:17:49 +0200
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Oct 20, 2010, at 16:53, aglee wrote:
> I tried the same thing in our WebView and got
>
> [<MyClass 0x4cea90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key foo.
>
> I suspect you can't use dot notation in JavaScript to access Objective-C properties, because window.myObject.foo would be ambiguous --
No, it isn't. When I call window.foo.bar, then window.foo is the reference in JS for the object, and bar is the property name, there's no ambiguity. It is even the way it should be accessed.
> is its value the property value, or is it the *function* that retrieves the property value?
This is the property, that should also be obvious from the JS statement I gave. As i said, I am talking about the key access, not the selector access.
Christiaan
> To illustrate, if in the JavaScript I do alert(window.myObject.foo), the alert message is:
>
> function foo() {
> [native code]
> }
>
> I played with this a while back but I don't remember what the docs said.
>
> --Andy
>
>
> On Oct 20, 2010, at 09:18 AM, Christiaan Hofman <[email protected]> wrote:
>
>> I am trying to make a key for an object available to javascript in a webview. I have been able to successfully do this for calling methods on the object, but exposing the key does not work. I have followed all the prescriptions in the documentation:
>>
>> - Implemented -webView:didClearWindowObject:forFrame: in the WebFrameLoadDelegate
>>
>> - (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowObject forFrame:(WebFrame *)frame {
>> [windowObject setValue:[FOO sharedInstance] forKey:@"foo"];
>> }
>>
>> - Implemented +isKeyExcludedFromWebScript: on the class (Foo) for the exposed object, returning NO for the (KVC compliant) key I want to expose.
>>
>> + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
>> return strcmp(name, "bar") != 0;
>> }
>>
>> Now when I try to set the key of the object in a JavaScript function on a page loaded in my webview (window.foo.bar = true), the KVC compliant setter is never called, and nothing happens. As I said, calling a function for an exposed selector from JavaScript does work, the method is properly called.
>>
>> Is this a bug, or has webkit stopped supporting this, or is there something else I forgot?
>>
>> thanks,
>> Christiaan
>>
>> _______________________________________________
>> MacOSX-dev mailing list
>> [email protected]
>> http://www.omnigroup.com/mailman/listinfo/macosx-dev