How to copy text to the client's clipboard using jQuery? [duplicate]

只愿长相守 提交于 2019-11-26 00:25:04

问题


This question already has an answer here:

  • How do I copy to the clipboard in JavaScript? 55 answers

The workflow is simple:

  1. You click inside a textarea.
  2. The text is copied to the client\'s clipboard.
  3. Display notice to the user.

How do you do it?


回答1:


Copying to the clipboard is a tricky task to do in Javascript in terms of browser compatibility. The best way to do it is using a small flash. It will work on every browser. You can check it in this article.

Here's how to do it for Internet Explorer:

function copy (str)
{
    //for IE ONLY!
    window.clipboardData.setData('Text',str);
}


来源:https://stackoverflow.com/questions/1539641/how-to-copy-text-to-the-clients-clipboard-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!