objective c - NSString returns empty with WebView Innerhtml -


i'm not hero objective-c please bare me i'm learning grips. although have great knowledge javascript, mac osx development seems hard.

i'm creating app relies on html5 , goal 'simply' save contents of specific div running javascript function. i've been searching everywhere , cannot seem find example me further or getting started. i'm hoping guys me point towards right direction.

ben taylor on twitter gave me starting code.

nsstring *html = [yourwebview stringbyevaluatingjavascriptfromstring:@"document.getelementbyid('nssidebar').innerhtml"]; nslog(@"contents:%@",html); 

the log returns empty. may because webview has not been loaded in order have string find 'some-element' div. current code be:

- (void)applicationdidfinishlaunching:()mywebview {      nsstring* filepath = [[nsbundle mainbundle] pathforresource:@"index"                                                          oftype:@"html"                                                     indirectory:@""];      nsurl* fileurl = [nsurl fileurlwithpath:filepath];     nsurlrequest* request = [nsurlrequest requestwithurl:fileurl];     [[webview mainframe] loadrequest:request];      nsstring *html = [webview stringbyevaluatingjavascriptfromstring:@"document.getelementbyid('nssidebar'.innerhtml"];     nslog(@"contents:%@",html);  } 

i hope me point right direction. if there's duplicate post - apologises , i'll remove topic.

two mistakes:

  1. you have syntax error: closing parenthesis missing.
  2. you need call .tostring() on returned object.

like this:

[webview stringbyevaluatingjavascriptfromstring:@"document.getelementbyid('nssidebar').innerhtml.tostring()"]; 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -