Sono bloccato a ottenere JS piuttosto semplice da eseguire nella mia UIWebView. In delegato della vista web, ho:UIWebView stringByEvaluatingJavaScriptFromString
- (void)webViewDidFinishLoad:(UIWebView *)wView {
NSString *someHTML = [wView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('box')[0]"];
NSString *allHTML = [wView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
NSLog(@"someHTML: %@", someHTML);
NSLog(@"allHTML: %@", allHTML);
}
ma quando viene richiamato il metodo, someHTML è pari a zero, mentre allHTML contiene l'intero corpo del HTML nella WebView.
ho eseguito il JS nella console Safari JS e funziona bene (si trova un div di 'scatola' di classe quindi so che i suoi in HTML)
Qualche suggerimento?
Maggiori informazioni:
FWIW, risultato in ciascuna delle seguenti è anche pari a zero
NSString *result = [self.webView stringByEvaluatingJavaScriptFromString: @"document"];
NSLog (@"1. result: %@", result); //should log the document object?
result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.body"];
NSLog (@"2. result: %@", result); //should log the document body
result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.body.getElementsByClassName"];
NSLog (@"3. result: %@", result); //should log a function
result = [self.webView stringByEvaluatingJavaScriptFromString: @"document.body.getElementsByClassName('box')[0]"];
NSLog (@"4. result: %@", result); //should log the node
puoi controllare anche questo http://stackoverflow.com/questions/10793698/how-to-make-image-maps-clickable-using-uiwebview-in-iphone –