Element.oncopy

  • Revision slug: Web/API/element.oncopy
  • Revision title: element.oncopy
  • Revision id: 405473
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Moved From DOM/element.oncopy to Web/API/element.oncopy

Revision Content

{{ DomRef }} {{ Fx_minversion_header(3) }}

Summary

The oncopy property returns the onCopy event handler code on the current element.

Syntax

element.oncopy = functionRef;

where functionRef is a function - often a name of a function declared elsewhere or a function expression. See JavaScript Reference:Functions for details.

Example

<!DOCTYPE html>
<html>
<head>
<title>oncopy event example</title>

<script>
function log(txt) {
    document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
}
</script>
</head>

<body>
<div oncopy="log('Copy blocked!'); return false;">Try copying this text!</div>

<h3>Log</h3>
<textarea rows="15" cols="80" id="log" readonly="true"></textarea>
</body>
</html>

This example prevents the text from being copied out of the browser window.

Notes

This event is sent when the user attempts to copy text.

Specification

Not part of specification.

See also

Revision Source

<div>{{ DomRef }} {{ Fx_minversion_header(3) }}</div>


<h2 id="Summary" name="Summary">Summary</h2>
<p>The <strong>oncopy</strong> property returns the onCopy event handler code on the current element.</p>


<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<em>element</em>.oncopy = <em>functionRef</em>;</pre>
<p>where <em>functionRef</em> is a function - often a name of a function declared elsewhere or a <em>function expression</em>. See <a href="/en-US/docs/JavaScript/Reference/Functions" title="JavaScript/Reference/Functions">JavaScript Reference:Functions</a> for details.</p>


<h2 id="Example" name="Example">Example</h2>
<pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;oncopy event example&lt;/title&gt;

&lt;script&gt;
function log(txt) {
    document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div oncopy="log('Copy blocked!'); return false;"&gt;Try copying this text!&lt;/div&gt;

&lt;h3&gt;Log&lt;/h3&gt;
&lt;textarea rows="15" cols="80" id="log" readonly="true"&gt;&lt;/textarea&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>This example prevents the text from being copied out of the browser window.</p>


<h2 id="Notes" name="Notes">Notes</h2>
<p>This event is sent when the user attempts to copy text.</p>


<h2 id="Specification" name="Specification">Specification</h2>
<p>Not part of specification.</p>


<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/DOM/element.oncut" title="DOM/element.oncut"><code>element.oncut</code></a></li>
  <li><a href="/en-US/docs/DOM/element.onpaste" title="DOM/element.onpaste"><code>element.onpaste</code></a></li>
</ul>
Revert to this revision