最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get clipboard contents with Greasemonkey - Stack Overflow

programmeradmin1浏览0评论

Is there the possbility to get the textual content of the clipboard to paste it automatically into a textarea clicking a button? Just found a method to copy data to it, but not to read data from it.

Is there the possbility to get the textual content of the clipboard to paste it automatically into a textarea clicking a button? Just found a method to copy data to it, but not to read data from it.

Share Improve this question asked May 5, 2014 at 14:45 Martin CupMartin Cup 2,5821 gold badge26 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

No, you cannot do this in javascript because it has proven to be a huge security hole.
Likewise, the developers of Greasemonkey are unlikely to add this capability for the same reasons.


You can write a Firefox add-on that does this, but I've never seen a (legit) use case.

A technique that works well for me is to have the Greasemonkey script set focus to the textarea (or input) and then I merely press CtrlV. It's super convenient and actually faster than grabbing the mouse to click a button.

You can try to implement this using the clipboard interface.

Please check this out:

  • https://developer.mozilla/en-US/docs/Web/API/Clipboard/readText#example
  • https://developer.mozilla/en-US/docs/Web/API/Clipboard/write#example
发布评论

评论列表(0)

  1. 暂无评论