omichelsen / angular-clipboard

Copy to clipboard with AngularJS directive, without using Flash.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do i feature detect if SelectionAPI or ClipboardAPI is supported by my browser without user interaction and hide the copy button if not available ?

siva-I opened this issue · comments

How do i feature detect if SelectionAPI or ClipboardAPI is supported by my browser without user interaction and hide the copy button if not available ?
Basically i want to disable the Copy button if the browser is old and doesn't support this feature.

Please advise

Unfortunately it seems that this is almost impossible to detect without some user interaction:
zeroclipboard/zeroclipboard#171
https://developers.google.com/web/updates/2015/04/cut-and-copy-commands

As a fallback, you may use navigator.userAgent up front to test that you have either Chrome 43+, Firefox 41+, Opera 29+ or IE10+.

The directive could implement this OOTB so we would not have to repeat this code in every project. E.g.

<button clipboard text="textToCopy" hide-if-not-supported="true">Copy</button>

or even

<button clipboard text="textToCopy" on-not-supported="doSomething()">Copy</button>

PR#26 might help you, with this you can do supported="supported" ng-show="supported".