What function does the Copy (HTML5) button execute?

What function does the Copy (HTML5) button execute?

jladburyjladbury Posts: 34Questions: 9Answers: 0
edited June 2018 in Buttons

I would like to duplicate the function of the Copy button elsewhere in my app. I have tried adding another button like this:
<button type='button' id='btnCopySurrogate' class='c8dataChooserButton'>Copy to Clipboard</button> $('#btnFileChooserSurrogate') .on('click', function () { $('.dt-button.buttons-copy.buttons-html5').trigger('click'); });
but this doesn't seem to work (i.e.there is no confirmation message).
In any case, a cleaner approach would be to define the new button with the actual function that the original Copy button executes, rather than triggering a click on the original.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    This is the function it executes. The document.execCommand part is the more interesting part - the rest is just data prep or backwards compatibility for old browsers.

    If you want to define a custom button docs for that are here.

    Allan

  • jladburyjladbury Posts: 34Questions: 9Answers: 0

    Thanks Allan.
    In the end, I got the surrogate button approach to work. A stupid error had prevented it, which an eagle-eyed reader might spot from my original post.
    Your reply prompted me to look further into clipboard APIs, and I discovered an async one in the pipeline which might become interesting:
    https://alligator.io/js/async-clipboard-api/

This discussion has been closed.