0

Is there method similar as

[textfield Inserttext:NSString]

in UIWebView?

Chan
  • 129
  • 3
  • 15
  • What are you trying to do? Simulate sending data to a web page that you loaded via `loadRequest`, or do you have some static HTML that you loaded via `loadHTMLString` that you want to change? In short, there's no direct analog to `insertText`, but it's probably more important to understand what you're trying to do, rather than what methods are there. – Rob Dec 25 '12 at 08:52
  • Hi Rob.. Sorry It's NSString :) Actually i'm trying to send text to UIWebView active textbox from custom keyboard. – Chan Dec 25 '12 at 08:55
  • 2
    @Chan You can try JavaScript injection using the `stringByEvaluatingJavaScriptFromString:` method of `UIWebView`. –  Dec 25 '12 at 08:58
  • Actually i have some javascript function to send data from custom Keyboard.It's perfect on normal website.It can show any text sent from custom keyboard. but my problem was my javascript cannot detect facebook comment plugin textbox. – Chan Dec 25 '12 at 08:59
  • This facebook comment plugin is more complicated than i think.It's use iframe and some funny funny thing. My javascript cannot detect on this funny funny thing. That's why i m looking perfect input method on any website, any textbox. – Chan Dec 25 '12 at 09:01
  • In that case you should have added that as well in the question. Also you might have to post the `stringByEvaluatingJavaScriptFromString` part. That will help others to look into this. – iDev Dec 25 '12 at 09:13
  • /* var txtarea = document.activeElement; txtarea.value='sometext from KB'; */ – Chan Dec 25 '12 at 09:19
  • It's main part of my script. I remove other unnecessary thing. get the current activeElement and assign value to this element. – Chan Dec 25 '12 at 09:22
  • @Chan I need your help. I have a same case. I have set my custom keyboard to UITextField and UITextView. but I cann't integrate with browser.Will you plz help me ? – Hiren Feb 05 '13 at 12:42
  • Hi Hi Ren, use javascript injection for uiwebview text – Chan Feb 06 '13 at 02:45
  • @Chan Actually I have never used javascript. can you please help me out for this – Hiren Feb 06 '13 at 05:05

1 Answers1

0

First:

Get the first responder. Get first responder

Second:

id responder = [UIResponder currentFirstResponder];
UITextRange *selectedTextRange = responder.selectedTextRange;
[responder replaceRange: textRange withText: @"text"];
Community
  • 1
  • 1
tomfriwel
  • 1,795
  • 2
  • 13
  • 42