views:

240

answers:

1

I'm hosting a webkit frame in my objective-C application and trying to execute some javascript on the loaded document using stringByEvaluatingJavaScriptFromString. Every call I make to document.getElementsByTagName('*') or document.getElementsByTagName('a') returns 0 length collections, regardless of the page I load in my webview. Other document methods seem to work (document.title, document.location.href, etc). The script returns the correct value in Safari, just not in my webview.

- (void)webView:(WebView *)webview didFinishLoadForFrame:(WebFrame *)frame{ 
        NSLog(@"anchor elements: %@", [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('a').length + '';"]); 
}

(in case you're wondering, the + '' is used to coerce the length into a string)

I've also tried

[[webView windowScriptObject] evaluateWebScript:@"document.getElementsByTagName('*').length + '';"] 

with the same results returning 0. Anyone know what's going on?

A: 

After much head smashing, I figured out the problem-- calls to document.getElement* from a different thread return no elements. Other methods still seem to work.

jeff