I'm trying to make it easy for an iphone user to copy some text to the clipboard in mobile safari. As in the usual "touch-hold-copy". There is a specific bit of text I want to a user to copy. I have full choice of the html markup in which to wrap the text. How can I make it easy, rather than abitrary? For instance:
Is there a way to "select all" the text upon touch-down using javascript? Then a user could just continue to touch-hold and then choose copy?
Is there a way to bring up the "select all" option? Like you can when typing in a text box? After which they can choose copy?
If there's no javascript solution, how can I arrange the html to help Safari select the right bit of text easily? As opposed to just a word, or a wrapping div?
I've tried onFocus="this.select()" for various elements, none seem to work. Also tried onClick.
Those who have tried to port a site that uses ZeroClipboard to the iPhone might have some ideas.
Cheers
In the Safari app on your Mac, go to a photo or image that shows text. The text can be words, a phone number, an email address, a website address, or a street address. Move the pointer over the text, then drag to select it.
Navigate to the page that you want to search. Tap the Share icon (the square with an arrow pointing out) at the bottom of the screen. Scroll past the Share options to the Action menu and select Find on Page. Type the word or phrase you're looking for in the search field and tap Search.
instead of this.select();
I used the following and it worked!
this.selectionStart=0;
this.selectionEnd=this.value.length;
The magic sauce for me was the combination of these three:
onFocus="this.selectionStart=0; this.selectionEnd=this.value.length;" <!-- for big screens -->
onTouchEnd="this.selectionStart=0; this.selectionEnd=this.value.length;" <!-- for small screens -->
onMouseUp="return false" <!-- to stop the jitters -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With