I am trying to create a copy function in pure JS, so there is no flash. The problem is that I do not want to show the copy button when the browser does not support copying to the clipboard.
I use the document.execCommand('copy') method to copy to the clipboard, but support for this is not the best. For example, safari has an execCommand function, but does not support the copy option. This means that I just can't just check if the function exists.
Due to this ingenious support, I think I will have to go along the path of discovering the browser, just like the github I came across when looking at the zeroclipboard . Here is the implementation I found.
Is there a correct way to detect a user agent? I would prefer not to use NavigatorID.userAgent as this is deprecated according to MDN .
javascript copy-paste
silverlight513
source share