Thursday, 16 June 2016

use js/ angularjs to copy into clipboard


for js:

https://clipboardjs.com/

for angular:

https://sachinchoolur.github.io/ngclipboard/

another way:

document.execCommand()


ngclipboard and clipboardjs are very similar

You can find a lot of samples and docs for this:

http://webdesign.tutsplus.com/tutorials/copy-to-clipboard-made-easy-with-clipboardjs--cms-25086

However, these libs are using a special way to make it work.

They don't support doing thing in js for example you can not construct a string in js and put into clipboard in onClick function or other js functions. You have to trigger the copy action by a html element, and users must click it to do the copy, and the value must from your html some places (another input box's value or tag's value). That is why all their examples have a input box and a button together.

ngclipboard and clipboardjs are the best libs for now, but they still do not support some of the browsers e.g. safari. because they are using document.execCommand().


No comments:

Post a comment