Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy to Clipboard that also works on Mobile?

I'm familiar with ZeroClipboard and jquery.copy, which both use Flash. OK, so I get it, for browser security reasons, copying is disallowed and we need Flash. But this means the copying functionality does not work in mobiles (iPhone, Android) or iPad.

Is there any resource or plugin that allows a simple Copy to Clipboard functionality on both modern browsers (include IE7+) and mobile browsers?

Thanks!

like image 760
PKHunter Avatar asked Oct 22 '12 16:10

PKHunter


People also ask

Does copy to clipboard work on mobile?

Android can cut, copy and paste text, and like a computer, the operating system transfers the data to the clipboard. Unless you use an app or extension like Clipper or aNdClip to retain your clipboard history, however, once you copy new data to the clipboard, the old information is lost.

How do you paste from clipboard on mobile?

To cut and paste on Android, tap and hold a word until highlighted, then drag the handles to highlight the desired text and tap Cut. In another app, tap and hold, then tap Paste.

How does cross device copy paste work?

Cross-device copy and paste requires the exchange of data between your PC and Android device. If you've allowed your devices to sync over mobile data, and you're not connected to a Wi-Fi network, then copy and paste will use data.

How do I copy and paste from phone to laptop?

Select and copy text from an app on your Android device. In Windows, open an application in which you can enter text. Press the Windows key and the V key to display the cloud clipboard. You should see the text you copied from Android.


1 Answers

There is not a great solution to do this without using flash. I would just keep it simple and allow your users to copy the text themselves. It's how google serves their analytics code to users to embed on their sites. I'm sure if there was a great way to do it that google would be using it.

Keeping it simple:

$(function(){
    $('.text').click(function(){
        $(this).select();
    });
});

Focus event: http://jsfiddle.net/khXjC/

Click event: http://jsfiddle.net/qjfgoeLm/

like image 200
tlaverdure Avatar answered Sep 26 '22 08:09

tlaverdure