Get notified when objective-c dom updates are ready initiated from webview

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-05-16T17:45:40Z Indexed on 2010/05/16 17:50 UTC
Read the original article Hit count: 333

I am programmatically updating the DOM on a WebKit webview via DOMElement objects - for complex UI, there is usually a javascript component to any element that I add. This begs the need to be notified when the updates complete -- is there any such event? I know regular divs dont fire an onload or onready event, correct? The other assumption I had, which may be totally wrong, is that DOMElement updates aren't synchronous, so I can't do something like this and be confident it will meet with the label actually in the DOM:

DOMElement *displayNameLabel = [document createElement:@"div"];
[displayNameLabel setAttribute:@"class" value:@"user-display-name"];
[displayNameLabel setTextContent:currentAvatar.avatarData.displayName];
[[document getElementById:@"user-card-content"] appendChild:displayNameLabel];
id win = [webView windowScriptObject];
[win evaluateWebScript:@"javascriptInstantiateLabel()"];

Is this true?

I am using jquery within the body of the html already, so I don't mind subscribing to a particular classes set of events via "live." I thought I might be able to do something like:

$(".some-class-to-be-added-later").live( "ready", function(){
    // Instantiate some fantastic javascript here for .some-class
});

but have experienced no joy so far. Is there any way on either side (objective-c since I don't programmatically firing javascript post load, or javascript) to be notified when the element is in the DOM?

Thanks, Josh

© Stack Overflow or respective owner

Related posts about webkit

Related posts about objective-c