How to copy a div's content to clipboard without flash

后端 未结 3 1409
逝去的感伤
逝去的感伤 2021-01-02 03:52

That\'s it :) I have a div with the id #toCopy, and a button with the id #copy. What\'s the best way to copy #toCopy conte

3条回答
  •  猫巷女王i
    2021-01-02 04:00

    UPDATED ANSWER Javascript was restricted from using the clipboard, early on. but nowadays it supports copy/paste commands. See documentation of mozilla and caniuse.com.

    document.execCommand('paste')
    

    make sure that you support browsers that don't.

    https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand http://caniuse.com/#search=command

    Javascript is not allowed to use the clipboard, but other plugins like flash do have access.

    How do I copy to the clipboard in JavaScript?

提交回复
热议问题