I am new to iPhone developer,
I am loading a webpage in my UIWebview,
After loading is done when user selects any text then i want to fetch that text,
here is my code snippet,
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect webFrame = CGRectMake(0.0, 0.0, 500.0, 500.0);
webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor greenColor]];
NSString *urlAddress = @"http://stackoverflow.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
NSString *t= [webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
NSLog(@"selected text=%@",t);
}
but my Log shows nothing when i selects any text.
Any help will be appreciated.
You should look into this Tutorial. Hope it helps you.