Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically trigger copy menu in iOS safari using javascript?

I'm trying to implement a user-friendly way to copy some text from a text input field to the clipboard on iOS/Safari. I understand there is no way to programmatically do it on this platform, but I was hoping I could guide the user experience as much as possible.

On iOS/Safari, when a user manually highlights some text, a contextual Copy menu pops up. I was hoping the same menu would pop up when the text is selected programmatically, but it doesn't. Is it even possible to do that?

If not, any advice on how to best implement a user-friendly experience to copy some text to the clipboard on iOS/Safari?

For reference, I'm selecting the text using the method described in this question: Programmatically selecting text in an input field on iOS devices (mobile Safari)

like image 343
Ariel Vardi Avatar asked Jul 11 '12 22:07

Ariel Vardi


1 Answers

It's not possible unfortunately. I'd include some informative text below the input, hopefully that will work out okay in terms of user-friendliness.

Another option would be to go native, e.g. by wrapping using PhoneGap, but I guess you are already well aware of that option. If so, something like this would work in native code:

[UIPasteboard generalPasteboard].string = @"your string";
like image 192
sandstrom Avatar answered Sep 28 '22 11:09

sandstrom