On 25/11/2008, at 12:32 PM, Pierce Freeman wrote:

Sorry for my newbie-ness, but I still don't really get what you are talking
about.  Are you saying that I should do this:

[WebView setFrameLoadDelegate:didFinishLoadForFrame];

- (void)didFinishLoadForFrame
{
  // Do stuff
}

No, you would do this:

[webView setFrameLoadDelegate:controller];

The controller object would be whatever object is controlling the web view. It's quite likely you'd just set the delegate to self.

Note that you calling the method on your WebView instance, not the WebView class, as -setFrameLoadDelegate: is an instance method.

You then have to implement the delegate method in your controller class:

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
        //when this method is called, the load of the webview is finished
        DOMDocument *dom = [sender mainFrameDocument];
        DOMElement* element= [dom getElementById:@"hiddenField"];
        NSString* elementValue=[element getAttribute:@"value"];
        
        //do something with elementValue
}

Note that this is asynchronous, the main thread will not wait for the - webView:didFinishLoadForFrame: method will be called. As already pointed out, if you need to block while waiting for the web view to load you'd need to do something like this instead of implementing the delegate:

[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.domain.com/page.html";]]];

//block while the webview loads
while ([webView isLoading])
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate: [NSDate distantFuture]];
}

DOMDocument *dom = [webView mainFrameDocument];
DOMElement* element= [dom getElementById:@"hiddenField"];
NSString* elementValue=[element getAttribute:@"value"];

//do something with elementValue


--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to