Notice: The Monaca & Onsen UI Community Forum is shutting down.
For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.
Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.
Copy to clipboard
-
Hi guys,
I am trying to implement a copy to clipboard button which should take the value of a textarea .
I tried both the clipboard.js library (https://clipboardjs.com/)var copiedtext = new Clipboard("#btn-copy");
and the plain javascript approach
$("#btn-copy").on('click', function(event) { var copyTextarea = $("textarea").select(); document.execCommand('copy'); });
but none is working on mobile.
Any suggestions or ideas?
-
@chriscarex I looked into your question and I’m afraid on a hybrid mobile app your only option is to use a Cordova plugin such as this one. Both
clipboard.js
and theexecCommand()
function work only on browsers.
-
@misterjunio amazing thanks I will give it a try!
-
cordova plugin add https://github.com/VersoSolutions/CordovaClipboard.git
module.controller('ClipboardCtrl', function($scope, $cordovaClipboard) { $cordovaClipboard .copy('text to copy') .then(function () { // success }, function () { // error }); $cordovaClipboard .paste() .then(function (result) { // success, use result }, function () { // error }); });
-
asdasd