--- title: element.oncopy slug: Web/API/HTMLElement/oncopy translation_of: Web/API/HTMLElement/oncopy ---
{{ ApiRef() }}
oncopy属性用来获取或设置当前元素的copy事件的事件处理函数.
element.oncopy = functionRef;
functionRef 是一个函数名或者函数表达式.
<html>
<head>
<title>oncopy示例演示</title>
<script>
  function log(txt)
  {
    document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
  }
</script>
</head>
<body>
<div oncopy="log('复制被阻止!'); return false;">试着复制这句话!</div>
<h3>Log</h3>
<textarea rows="15" cols="80" id="log" readonly="true"></textarea>
</body>
</html>
上例演示了如何禁止复制浏览器中的一段话.
当用户尝试复制选中元素或文本时会触发copy事件.
不属于任何公开的规范.
{{ languages( { "ja": "ja/DOM/element.oncopy", "en": "en/DOM/element.oncopy" } ) }}