Javascript Copy To Clipboard on safari?

前端 未结 7 930
执念已碎
执念已碎 2020-12-10 02:30

It may be duplicate question but i didnt find the solution for this.

I am trying to copy text on button click. Its working on chrome, mozilla(working on on windows a

相关标签:
7条回答
  • 2020-12-10 03:28

    using the copy event seems to work for me.

    window.addEventListener('copy', (event) => {
      event.preventDefault();
      event.clipboardData.setData('text/plain', `foo: ${Date.now()}`);
    });
    click here, press Cmd-C, paste outside the browser

    tested in Chrome 83, Safari 13.1, Firefox 77

    0 讨论(0)
提交回复
热议问题