2

I am loading HTML content in UIWebView. My page contains UIButton and UIWebView containing some HTML content. UIWebView is editable, so user can move to particular content of UIWebView.

What I actually want to do so, on button click text(suppose XYZ) should be added at that particular position in UIWebView.

Thanks in advance

Ankita Shah
  • 2,178
  • 3
  • 25
  • 42
  • use webView stringByEvaluatingJavaScriptFromString – santhu Feb 10 '14 at 11:07
  • I had already used that to load my static html. But I want to add text on UIButton click at user's cursor position in UIWebView. – Ankita Shah Feb 10 '14 at 11:16
  • 1
    to load html , you use, loadHTMLString method not stringByEvaluatingJavaScriptFromString method. First write some method in javascript which writes some text at cursor position and now call that method from Objective C using stringByEvaluatingJavaScriptFromString method – santhu Feb 10 '14 at 11:26

2 Answers2

1

 I hope this will give you an idea to create a system like that, not tested.

NSString *stringData = @"this is test content"; 
[webView stringByEvaluatingJavaScriptFromString:
 [NSString stringWithFormat:@"myJSFunction(%@)", stringData]];
Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
1

I was using tinyMCE editor. So I had added below code on UIButton click, which solved my problem.

   NSString *strhtml=[NSString stringWithFormat:@"tinymce.activeEditor.execCommand('mceInsertContent', false, '%@');",@"Good Morning"];
  [self.webView stringByEvaluatingJavaScriptFromString:strhtml];
Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
Ankita Shah
  • 2,178
  • 3
  • 25
  • 42