Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

The copy event is fired when the user initiates a copy action through the browser UI (for example, using the CTRL/Cmd+C keyboard shortcut or selecting the "Copy" from the menu) and in response to an allowed document.execCommand('copy') call.

General info

Specification
Clipboard
Interface
ClipboardEvent
Bubbles
Yes
Cancelable
Yes
Target
Element: the focused element (for contentEditable elements - the element containing the start of the selection), or the <body> element.
Default Action
See below.

A handler for this event can modify the provided ClipboardEvent.clipboardData object by calling setData(format, data):

document.addEventListener('copy', function(e){
    e.clipboardData.setData('text/plain', 'Hello, world!');
    e.clipboardData.setData('text/html', '<b>Hello, world!</b>');
    e.preventDefault(); // We want our data, not data from any selection, to be written to the clipboard
});

A handler for this event cannot read the clipboard data using clipboardData.getData().

The event's default action depends on the source of the event and the handler's behavior:

  • A synthetic copy event does not have a default action; otherwise
  • If the event was not cancelled: copies the selection (if any) to the clipboard;
  • If a handler cancelled the event and called setData(): copies the contents of clipboardData to the clipboard;
  • If a handler cancelled the event without calling setData(): no action.

Properties

Property Type Description
target Read only EventTarget The event target (the topmost target in the DOM tree).
type Read only DOMString The type of event.
bubbles Read only Boolean Whether the event normally bubbles or not
cancelable Read only Boolean Whether the event is cancellable or not?

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) ? ? ?
clipboardData (Yes) 22 (22) No support ? ?
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? (Yes) ? ? ?
clipboardData ? 22.0 (22) ? ? ?

文档标签和贡献者

标签: 
 此页面的贡献者: Nickolay, teoli, Sheppy, ethertank, louisremi
 最后编辑者: Nickolay,