• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Call getElementById in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Call getElementById in Cocoa


  • Subject: Re: Call getElementById in Cocoa
  • From: Rob Keniger <email@hidden>
  • Date: Tue, 25 Nov 2008 18:44:05 +1000


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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Re: Call getElementById in Cocoa (From: Pierce Freeman <email@hidden>)

  • Prev by Date: Re: CGImageDestinationSetProperties does not work for animated GIF
  • Next by Date: Re: Killing a Thread
  • Previous by thread: Re: Call getElementById in Cocoa
  • Next by thread: CALayer containing a view
  • Index(es):
    • Date
    • Thread