简体   繁体   中英

How to copy text to clipboard via custom context menu (without flash / add-ons)

My understanding is that there is no cross browser * solution for setting the text of system clipboard directly, instead, on a keyboard initiated copy event, setting text to the system clipboard can be accomplished by setting focus to a hidden text input on keypress just prior to the copy event.

With 'copy' from custom context menu, there is no user-initiated copy event to be directed towards the hidden input.

In Google docs, however, right click opens a custom context menu, where the user can copy the selected text to the system clipboard. How can this result be achieved?

  • (Google Chrome (v28.x), Mozilla Firefox (v22.x) current versions as of this writing, Internet Explorer 10)

There is no cross browser way around for accessing system clipboard without flash. Clipboard is a security-relevant resource since it could contain sensitive data.

You can find more info in this blog post :

http://brooknovak.wordpress.com/2009/07/28/accessing-the-system-clipboard-with-javascript/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM