A _javascript_ property is not the same as an element attribute.

It is unfortunate that some attributes like "onclick" get mapped from attributes to properties, but this is a special case for compatibility. But if you later change the onclick property the attribute doesn't change.

The equivalent of 'myObject.command = value' in ObjC is '[myObject setValue:value forKey:@"command"]'. Then the matching call '[myObject valueForKey:@"command"]' to get the value back.

_javascript_ has the same setAttribute and getAttribute methods if you do want to change an attribute. Hope this helps.

— Timothy Hatcher


On Oct 26, 2006, at 8:47 AM, Rudi Sherry wrote:

I'm working with a WebView where I use DOM object manipulation in objective-c combined with _javascript_.

I have the dom document and I add an object with some attributes like this:

DOMNodeList *list = [ domDoc getElementsByTagName: @"BODY" ];
DOMNode *body = [ list item: 0 ];
myObject = (DOMHTMLObjectElement *) [ [ domDoc createElement: @"OBJECT" ] retain ];
[ myObject setAttribute: @"ID"@"MyObjectName" ];
[ myObject setAttribute: @"NAME"@"MyObjectName" ];
<snip>
[ myObject setAttribute: @"command" : @"xxx" ];
[ body appendChild: myObject ];

In the _javascript_, I can get the object with this and check its value (this is in a _javascript_ function that gets called):

var myObject = document.body.children['MyObjectName'];
alert(myObject.command);
myObject.command = "abcdef";
alert(myObject.command);

I have a WebUIDelegate with the runJavaScriptAlertPanelWithMessage that prints out the alert value and compares it against myObject:

- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message
{
NSLog (@"alert: %@", message);
NSLog( @"command attribute: %@", [ mSwfObject getAttribute: @"command" ] );
}


In the above example, it prints out:

2006-10-26 08:44:29.771 TestInsideWebKit[9235] alert: xxx
2006-10-26 08:44:29.771 TestInsideWebKit[9235] command attribute: xxx
2006-10-26 08:44:29.771 TestInsideWebKit[9235] alert: abcdef
2006-10-26 08:44:29.771 TestInsideWebKit[9235] command attribute: xxx


Why isn't the command attribute changed in the objective-c object when it's changed in the _javascript_ function?  It must be the same object since it started as 'xxx'.

Any help would be appreciated,

Thanks,
Rudi

_______________________________________________
webkit-dev mailing list

_______________________________________________
webkit-dev mailing list
webkit-dev@opendarwin.org
http://www.opendarwin.org/mailman/listinfo/webkit-dev

Reply via email to